1

我写了一个自定义控件,我希望能够在设计器中设置一个 Icon 属性。这个属性应该让我可以选择从嵌入式资源中选择一个图标,就像图片框控件(属性图像)一样,但我似乎无法弄清楚如何实现这一点。

不幸的是,网上没有很多关于创建具有丰富设计时支持的控件的信息,但我确实找到了关于 TypeConverters、TypeEditors 的信息,但没有人告诉我如何实现我想要的。

谁能指出我正确的方向?

4

2 回答 2

2

如果您正在寻求类似的PictureBox控制,则不需要任何东西,请尝试以下操作:

public class SimpleImage : Control
{

    public Image Image { get; set; }

}
于 2011-01-17T12:51:51.787 回答
0

要将图标添加到控件,您可以将控件和图像文件部署为单独的文件、使用系统控件中的图像或将图像作为程序集的一部分。

<ToolboxBitmap("c:\MyIcon.bmp")> _
   Public Class MyUserControl
      Inherits System.Windows.Forms.UserControl

       ' Code for the control.
   End Class

从资源加载

 <ToolboxBitmap(GetType(MyNameSpace.MyUserControl),"MyIcon.bmp")> _
   Public Class MyUserControl
      Inherits System.Windows.Forms.UserControl

      ' Generate code
      ' Code for your control.
   End Class

这是有关更多详细信息的网址 http://support.microsoft.com/kb/311315

于 2011-01-17T14:31:24.563 回答