Saturday, July 19, 2008

How to add custom control in Visual Studio Toolbox.

How to add custom control in Visual Studio Toolbox.

In my previous article Creating Custom Controls in ASP .Net  we have seen the technical approach for creating custom control and  in How to make better appearance of your custom control in Visual Studio we have gone through the design aspects of custom control.

Now in this article I will explain how to add your custom control to your Toolbox.


Making Custom Control Class Library Project.

Step 1 - Create a class library project named myControlLib.

Step 2 - Add the following code to a new class named myImage. To download sample code files click here. After downloading add “myImage.cs” and “myImageLogo.bmp” file to your “myControlLib” project. Change the “Build Action” property of “myImageLogo.bmp” to Embedded Resource.

Step 3 - Compile the project.

Note: Above given steps are specific to the code sample that I have created. If you want to rename any of the file or change any other aspects than make sure that you also change the design time attributes of your control.

Example: [Designer ("myControlLib.myImageDesigner,myControlLib")] uses the namespace “myControlLib” that is directly related to the name of the class library project you make.


Adding custom control to toolbox.

Step 1 - Switch over to the web project in which you want to use the control.

Step 2 - In toolbox add your own tab or click on general tab.

Step 3 - Right click in the selected tab area and click Chose Items.



Step 4 - This will open Choose Toolbox Item screen. Click on Browse button and specify the path of dll you created in your myControlLib project.





Step 5 - Click Ok and you’re done. Your Custom control will be added to the toolbox as shown below.



21 comments:

Shabana said...

Nice One. It help me a bit...

Hybrid said...

how to compile more then one control in one dll?
when i build dll with 2 controls, toolbox adds only 1 control

Hybrid said...

nvm, all works fine :D

Bharath said...

How can we load the WPF custom controls programatically?

Schnoid said...

Magic, cheers for the assistance.

Nauman khattak said...

Thanks dear

V.S.Pavithra said...

Cool one!! It really helped me a lots!!

Sunil said...

Thanks it helped me.

Mike Schneider said...

This was a big help. Thank you very much.

2010 in review « Dhaval Upadhyaya said...

[...] The busiest day of the year was October 7th with 93 views. The most popular post that day was How to add custom control in Visual Studio Toolbox.. [...]

David said...

Is this is the same in VS 2010 ?

Dhaval Upadhyaya said...

Yes

deepak sharma said...

how can we play swf file in VS 2008 with c# in desktop application

Vijay said...

Superrr!!

Viet Vo Quoc said...

Hello Dhaval Upadhyaya!
That's very cool but i have the problem is I want to create a component like this:






How to do that??Hope reply soon!

Viet Vo Quoc said...

I mean i want to have a component but it have a tag child in it?? look like the "li" lie inside "ul" tag.Cna you give me some advice??please soon!!

madhan said...

hi, when i try to add the dll file , its showing the dll file is not a microsoft component and not adding the tool... :( .. plz help me out

madhan said...

m using visual studio 2010

Arnold said...

Not working at all!

I'm using Visual Studio 2010

seema trivedi said...

superb! thank you soooooooooooooo much..

hkcff.org said...

I like the helpful info you provide in your articles.
I will bookmark your blog and check again here regularly.

I'm quite sure I'll learn many new stuff right here! Best of luck for the next!