Sometimes we
When a third-party control is added to the toolbox of vs2005, a custom icon is displayed.
Without any processing, we use the default icon when generating the control and placing it in the toolbox. It looks a little ugly.
How do I customize icons?
The toolboxbitmap attribute is used.
Use toolboxbitmap
Using system. drawing;
First, prepare a BMP file with the same name as your control type.
For example
- Public class mywebcontrol: webcontrol
- {
- }
Type, your BMP file must be
Mywebcontrol.bmp
Now you can use toolboxbitmap
Now
- [Toolboxbitmap (typeof (mywebcontrol), "mywebcontrol.bmp")]
- Public class mywebcontrol: webcontrol
- {
- }
Mywebcontrol.bmp is stored in the root directory.
If your
Mywebcontrol.bmp must be referenced in this way in other directories, for example, in the icon
Directory
- [Toolboxbitmap (typeof (mywebcontrol), "icon.mywebcontrol.bmp")]
After compilation, drag it to the toolbox to test the compiler.
There are other methods that do not use the toolboxbitmap attribute.
Use a bitmap image (not an icon)
Images, embedded resources) files
For example, if you have a namespace lemongtreecontrol and the custom control is bar.
1: create an image named bar.bmp according to the above image rules and add the image to your project,
2: Set the bar.bmp image setting property generation operation to "embedded resource"
3: note that the namespace of the image must be lemongtreecontrol.
4: If the namespace of the control does not match the default namespace of the project, you must set the bitmap
Move the image to the appropriate subdirectory to match the image. If this method is invalid, you obviously cannot use this technology to implement your custom image. You can use the toolboxbitmap below
Attribute Technology
5: Indicate the icons in the toolbox that I used directly in the root directory.
The above simple technology is used to meet your needs, and you do not need to use toolboxbitmapattribute to generate your type.