将图像分配给复合自定义控件 c# VS .NET 2013

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

问题涉及 Windows 表格。

我不知道该怎么做。我试过以下方法:

1)添加一个Bitmap(CarControl.bmp)做解决方案,然后设置BuildAction嵌入式资源 并添加 ToolBoxBitmapAttribute,如:

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

2) 进入 Properties,然后在 Resources 部分我添加了一些图像。还是不行。

有人可以帮忙吗?

命名很重要,否则起不了作用

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

另一个重要提示:

如果您打开 CarControl 的解决方案,您将始终看到实际构建控件的默认齿轮图标。但是,如果您进行构建并通过拖放 dll 或 Right click/Choose Items...[=30= 将此(已发布)库的控件添加到工具箱], 然后会出现图标。

如果一切顺利,用Reflector或其他反汇编工具打开编译后的.dll时,您将能够在编译后的.dll中找到嵌入的资源。以下示例来自 System.dll:

你应该在这里找到 <DefaultNamespace of your project>.<Your resources folder>.CarControl.png