我一直在这方面工作但似乎无法弄明白!
我的解决方案看起来像以下布局......
Solution 'Gen' (2 projects)
'-> MyControls
'-> graphics
'-> UserControl1.bmp
'-> UserControl1.cs
'-> Gen
'-> MainGUI.cs
我想简单地制作一个工具箱图标,这样我就可以在工具栏上看到一个漂亮的图标而不是蓝色的齿轮(默认的工具箱图标)。
我目前采取的步骤......
1。创建了一个位图图像:
我制作了16x16像素的16色(4位)图像。
2。将图像嵌入资源:
单击Solution Explorer窗口中的图像,然后在属性窗口中,我将Build Action更改为“Embedded Resource”。
第3。添加用于修复GetImageFromResource()方法中的错误的内部类:
在命名空间声明之前,我添加了以下行...
internal class resfinder
{
}
4。添加类属性'ToolboxBitmap':
在课堂宣言之上......
public partial class UserControl1 : UserControl
我添加了以下内容......
[ToolboxBitmap(typeof(resfinder), "Gen.graphics.UserControl1.bmp")]
5。建设项目:
在Build菜单下,我使用了“Rebuild Solution”。
完整的代码块
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
internal class resfinder
{
}
namespace Gen
{
[ToolboxBitmap(typeof(resfinder), "Gen.graphics.UserControl1.bmp")]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
}
}
结果:
当我尝试在MainGUI.cs表单上使用它时,我仍然有一个小蓝色齿轮作为工具箱图标。
来源:
答案 0 :(得分:2)
似乎答案很简单......我实际上已经做好了一切!
虽然有一件值得注意的事情......
如果您使用的是参考,则不会显示自定义工具箱图标 在同一解决方案中的项目。
要修复/解决此问题,您需要执行以下操作...
添加对已编译的引用(自定义控件的产品) 项目)DLL文件。
我最终在编译后删除了自定义控件项目,然后添加了我想要在其上使用它的项目的引用。在我这样做后,我右键单击工具箱,然后单击"选择项目..."。然后单击Browse并从那里加载DLL。
现在,自定义工具箱图标显示正常!