【发布时间】:2012-12-16 12:49:44
【问题描述】:
我有一个 Windows 窗体应用程序。我在我的项目中添加了一个名为 MyLibrary.cs 的类,我继承了 System.ComponentModel.Component 这个类,我还添加了一个位图图像,其构建操作设置为 EmbeddedResource 到我的资源文件夹,但是当我编写下面的代码并构建项目当我想将我的组件拖放到我的表单时,我的自定义图标不会改变。你能帮帮我吗?
我检查了很多链接,例如 http://msdn.microsoft.com/en-us/library/system.drawing.toolboxbitmapattribute.aspx 和 How to find the elusive ToolboxBitmap icon,但没有一个对我有用!
这是我的代码:
MyLibrary.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
internal class resfinder
{
}
namespace MyForm
{
[System.Drawing.ToolboxBitmap(typeof(resfinder),"MyForm.Bitmap1.bmp")]
public class MyLibrary:System.ComponentModel.Component
{
}
}
【问题讨论】:
-
不要在字符串中包含命名空间名称,这就是第一个参数的用途。所以只是“Bitmap1.bmp”。使用 ildasm 仔细检查资源名称,在清单中找到 .mresource。
-
我做到了,但没有成功!你能给我一个新的指令来做这个吗?一个改变我的组件图标的指令。非常感谢你的关心 Hans Passant 先生.
标签: c# attributes components embedded-resource