How to customize custom icons for custom controls in the toolbox

Source: Internet
Author: User

Many friends write their own controls for their own use, but all the controls by default in the toolbox picture is a single icon-gear. How to customize custom icons for custom controls in the toolbox

Background: When I wrote a control with a progress bar with digits in the middle, I suddenly found that the charts added to the toolbox were a bit simple, as a result, how to use a custom graph to create a toolbox graph is generated, and a large amount of information is queried. this article is a little different from the original article. I modify some of the bugs and use my own instance to describe them below. you can do this in different ways. In the following example, bitmap or icon images must follow the following rules: 1. Bitmap Or Icon size cannot be 16 colors 16x162. The background color must be transparent. 1: you do not need to use a special toolboxbitmapattribute class to implement a bitmap image (which cannot be an icon image or an embedded resource. for example, if you have a namespace carrynoprogrambar and the custom control is bar. The image setting attribute generation operation of the project is set to à embedded resource 3. Note that the namespace of the image must be carrynoprogrambar4. If the namespace of the control does not match the default namespace of the project, you must move the bitmap image to the appropriate subdirectory for matching. If this method is ineffective, you obviously cannot use this technology to implement your custom images. You can use the toolboxbitmap attribute technology below to implement 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, instead of using toolboxbitmapattribute to generate your type technical solution 2: use the toolboxbitmap attribute to embed a bitmap image with the same name as the type rather than the icon. The default namespace is carrynoprogrambarnamespace carrynoprogrambar {[toolboxbitmap (typeof (bar)] public class bar: when the usercontrol )..htm example is running, a resource image named "bar.bmp" is stored in your project root directory. Note that the consistency between your images and the control namespace. Example 2 if you need a subdirectory in the project to put your image, you can change it to namespace carrynoprogrambar {[toolboxbitmap (typeof (bar), "sub.bar.bmp")] public class bar: usercontrol {......}} or [toolboxbitmap (typeof (bar), "sub. bar. ICO ")] by using sub-directories, you can use special resources, including ICO files, note that I have used a sub-directory example 3. Sometimes your controls and images are not in the same namespace, in the following scenario, you must use the same type of embedded resource image in a uniform namespace. The default namespace is namespace myassemblynamespace {public class sometype {...}} namespace differentnamespace {[toolboxbitmap (typeof (sometype), "bar. ICO ")] public class bar: usercontrol {...}}

 

 

Http://blog.donews.com/utilities/archive/2004/02/04/2621.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.