【问题标题】:ToolBoxBitmap Attribute does not work in my componentToolBoxBitmap 属性在我的组件中不起作用
【发布时间】:2012-12-16 12:49:44
【问题描述】:

我有一个 Windows 窗体应用程序。我在我的项目中添加了一个名为 MyLibrary.cs 的类,我继承了 System.ComponentModel.Component 这个类,我还添加了一个位图图像,其构建操作设置为 EmbeddedResource 到我的资源文件夹,但是当我编写下面的代码并构建项目当我想将我的组件拖放到我的表单时,我的自定义图标不会改变。你能帮帮我吗?

我检查了很多链接,例如 http://msdn.microsoft.com/en-us/library/system.drawing.toolboxbitmapattribute.aspxHow 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


【解决方案1】:

你应该看看 here 它说:

  1. 位图必须是 16x16

  2. 如果同时指定 Type 和字符串,则控件会在包含由 Type 参数指定的类型的程序集中搜索名称由 string 参数指定的图像资源

因此,请确保您的位图与“resfinder”位于同一程序集中,并确保在构建操作下的属性中将其设置为嵌入式资源

【讨论】:

    猜你喜欢
    • 2021-08-02
    • 2020-03-29
    • 2021-06-03
    • 2016-06-15
    • 1970-01-01
    • 1970-01-01
    • 2017-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多