简体   繁体   中英

Assigning an image to the composite custom control c# VS .NET 2013

The problem concerns Windows Forms.

I have no idea how to do it. I've tried following:

1) Add a Bitmap ( CarControl.bmp ) do the solution, then set BuildAction to Embedded Resource and add the ToolBoxBitmapAttribute like:

 [ToolboxBitmap(typeof(CarControl),"CarControl")]

2) Going into Properties , then in Resources section I've added some images. Still doesn't work.

Can anybody help?

Naming is very important, otherwise it does not work.

[ToolboxBitmap(typeof(CarControl), "Resources.CarControl.png")]

性质

Another important note:

If you open the solution of your CarControl you will always see the default gear icons for the controls of your actual build. But if you make a build and you add the controls of this (released) library to the Toolbox either by drag-and-dropping the dll or by Right click/Choose Items... , then the icon will appear.

If you did everything well, you will able to find the embedded resource in the compiled .dll when you open it with Reflector or other disassembler tool. The following example is from System.dll: 资源反编译

You should find a <DefaultNamespace of your project>.<Your resources folder>.CarControl.png here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM