Project summary [5] - How to customize personalized icons for custom controls in the toolbox

zhaozj2021-02-16  66

Many friends write their own controls, but all controls default to images in the toolbox are single icons - gears. How to customize personalized icons for custom controls in the toolbox

Background: The author is a bit single, which is a bit single, which is a single single, which is a single order, which has generated how to do the toolbox, which is the toolbox. A large amount of information, translated herein. This article is a bit in the original text, I modify some of these bugs, switch to my own instance to do the following description.

Below you can do with different methods. In the following example, Bitmap or ICON images must follow the rules below.

1, Bitmap or ICON size is omitted 16 color 16 x 16

2, the background color must be transparent

Technical Solution 1: With a Bitmap picture (cannot be an icon picture, embedding resources) file

You don't need to use a special ToolboxBitmapattribute class to be implemented.

For example, you have a namespace Carrynoprogrambar, custom controls for BAR projects.

1 Follow the image rules to create a picture named bar.bmp, add this image to your project,

2 Set the picture of this bar.bmp to generate an operation to à embedded resource

3 Note that the namespace of the picture must be Carrynoprogrambar

4 If the namespace of the control and the default namespace of the project do not match, you must move the Bitmap image to the appropriate subdirectory to make them match. If you use this method to be invalid, it is clear that you can't use this technology to implement your custom image, you can implement the following Toolboxbitmap property technology

5. Statement I use the icon in the toolbox directly taken in the root directory.

Simple technology above to achieve your needs, do not need you to use ToolboxBitMapattribute to generate your type

Technical Solution 2:

Use ToolboxBitmap properties

Use one and type with the same name Bitmap image instead of Icon embed resources, the default namespace is Carrynoprograbar

Namespace carrynoprogrambar {

[ToolboxBitmap]]

Public Class Bar: UserControl {...}

}

In the above example, it is assumed that there is a name bar.bmp embedded in the root directory, pay attention to the consistency of your image and control namespace

Example 2 If you need a picture in the project, you can modify it

Namespace carrynoprogrambar {

[Toolboxbitmap (TypeOf (Bar), "Sub.Bar.Bmp")]]

Public Class Bar: UserControl

{...}

}

or

[Toolboxbitmap (Typeof (Bar), "Sub.Bar.ico"]]

With subdirectory, you can use special resources, of course, include ICO files, you must note that I use a subdirectory on it.

Example 3

Sometimes your controls and pictures are not in the same namespace, in the following case you have to use the same type of embedded resource in the unified namespace

Default namespace

Namespace myassemblynamespace {

Public Class Sometype

{...}

}

Namespace Differentnamespace

{

[ToolboxBitmap (TypeOf (Sometype), "Bar.ico")]

Public Class Bar: UserControl

{...}

}

This author recommends please use the same namespace directly to call the icon problem in the toolbox.

转载请注明原文地址:https://www.9cbs.com/read-23004.html

New Post(0)