简体   繁体   English

ToolBoxBitmap 属性在我的组件中不起作用

[英]ToolBoxBitmap Attribute does not work in my component

I have a Windows Form application.我有一个 Windows 窗体应用程序。 I've added a class to my project named MyLibrary.cs and I inherited this class of System.ComponentModel.Component and I've also added a bitmap image with its build action set to EmbeddedResource to my resources folder, but when I write the code below and build the project my customized icon does not change when I want to drag and drop my component to my Form.我在我的项目中添加了一个名为 MyLibrary.cs 的类,我继承了 System.ComponentModel.Component 的这个类,我还添加了一个位图图像,其构建操作设置为 EmbeddedResource 到我的资源文件夹,但是当我编写下面的代码并构建项目,当我想将我的组件拖放到我的表单时,我的自定义图标不会改变。 Would you please help me?你能帮我吗?

I've checked a lot of links like http://msdn.microsoft.com/en-us/library/system.drawing.toolboxbitmapattribute.aspx and How to find the elusive ToolboxBitmap icon but none of them worked for me!我检查了很多链接,如http://msdn.microsoft.com/en-us/library/system.drawing.toolboxbitmapattribute.aspx如何找到难以捉摸的 ToolboxBitmap 图标,但没有一个对我有用

Here is my code:这是我的代码:

MyLibrary.cs我的图书馆.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 
    {

    }
}

You should look here it says:你应该看看这里它说:

  1. The bitmap must be 16x16位图必须是 16x16

  2. If you specify both a Type and a string, the control searches for an image resource with the name specified by the string parameter in the assembly containing the type specified by the Type parameter如果同时指定 Type 和 string,则控件会在包含 Type 参数指定的类型的程序集中搜索具有 string 参数指定名称的图像资源

So make sure your bitmap is located in the same assembly as "resfinder" and also put make sure in properties under build actions it is set as an Embedded Resource因此,请确保您的位图与“resfinder”位于同一程序集中,并确保在构建操作下的属性中将其设置为嵌入式资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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