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.
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:
Nice One. It help me a bit...
how to compile more then one control in one dll?
when i build dll with 2 controls, toolbox adds only 1 control
nvm, all works fine :D
How can we load the WPF custom controls programatically?
Magic, cheers for the assistance.
Thanks dear
Cool one!! It really helped me a lots!!
Thanks it helped me.
This was a big help. Thank you very much.
[...] 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.. [...]
Is this is the same in VS 2010 ?
Yes
how can we play swf file in VS 2008 with c# in desktop application
Superrr!!
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!
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!!
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
m using visual studio 2010
Not working at all!
I'm using Visual Studio 2010
superb! thank you soooooooooooooo much..
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!
Post a Comment