Help adding a component

  • Thread starter Thread starter Keith Smith
  • Start date Start date
K

Keith Smith

I am reading this article...

http://www.codeproject.com/cs/combobox/csautocomplete.asp

About half-way down you will see a section titled "Using This Control"
(written in orange lettering).

Underneath that it says "Use this control in the same manner as you would a
regular System.Windows.Forms.ComboBox. Add it to your form, via the designer
or programmatically as detailed below".

Which brings me to my question...I don't want to add the control
programmatically. How do you do it using the designer? Normally I would
drag it from the toolbar on the left, but in this case (I guess because it
is a custom control) it is not there.

Thanks!
 
If you right-click inside the Toolbox (where the textbox, combobox, etc
are) - there is a menu item "Choose items..." - choose that, and find the
DLL that has your controls - that will load it into the "Toolbox"..
 
If you right-click inside the Toolbox (where the textbox, combobox, etc
are) - there is a menu item "Choose items..." - choose that, and find the
DLL that has your controls - that will load it into the "Toolbox"..

Oh, I think I see. Mine is actually a little different than you are
describing. Mine has "Add/Remove Components"...but either way it does let
me browse for a DLL file.

So, then in order to use the code I have pasted I would need to put the code
in a DLL? Could you take me through those steps? Unless it is to
time-consuming to type here then maybe you could point me to a good link?
 
Keith Smith said:
Oh, I think I see. Mine is actually a little different than you are
describing. Mine has "Add/Remove Components"...but either way it does let
me browse for a DLL file.

So, then in order to use the code I have pasted I would need to put the
code in a DLL? Could you take me through those steps? Unless it is to
time-consuming to type here then maybe you could point me to a good link?
 
Yeah, that's right - I've been using 2005 beta for a while and am already
used to that!

OK, basically, you just need to make a class library, or anything that
compiles to a DLL. But you can also create a new project file and create a
"Windows Control Library", all that does is make the project type a dll and
auto-adds a starter "User Control".

If you're familiar with old-school stuff, with ActiveX controls - you needed
to compile an OCX that would have your controls within it. In the new world,
you can put controls in ANY dll. So that means you could have a support dll
that has some business logic like say MyCompanySupport.dll - you could also
put windows controls in that dll. you don't need to have a seperate file for
that.

To work backwards, when you right-click and choose "Add/Remove components",
and when you browse for a your DLL, when you click OK - it scans that dll
you chose and sees if there are any windows controls it can load from it.


So how do "make" a windows control? Well you can either extend an existing
control by inheriting from it. Try that by creating a new class (just an
empty, regular class - normally called "Class1"). Then change:

public class Class1

to be

public class Class1 : System.Windows.Forms.ComboBox

Now, you will have an addable component called "Class1" that will look/act
just like a combo box.

To make your own control (again, the same concept as an old-school ActiveX
control) - right-click on your project and add a new class, but choose "User
Control". Draw whatever you need to on that, and again - once compiled, that
will show up as an icon in the toolbox.


Hope that helps..
 
Back
Top