如果希望在“工具箱”中为控件显示特殊图标,可以通过使用 来指定一个特定的图像。此类是一种属性,这是一种可以附加到其他类上的特殊类。有关属性的更多信息,对于 Visual Basic 请参见 ,对于 Visual C# 请参见 。
通过使用 ,可以指定一个字符串来指示一个 16 x 16 像素位图的路径和文件名。此位图在添加到“工具箱”后显示在对应的控件旁边。还可以指定 ,在这种情况下会加载与该类型关联的位图。如果您同时指定 和字符串,则控件在包含由 参数指定的类型的程序集中搜索其名称由 String 参数指定的图像资源。
// Specifies the bitmap associated with the Button type.
[ToolboxBitmap(typeof(Button))]
class MyControl1 : UserControl
{
}
// Specifies a bitmap file.
[ToolboxBitmap(@"C:\Documents and Settings\Joe\MyPics\myImage.bmp")]
class MyControl2 : UserControl
{
}
// Specifies a type that indicates the assembly to search, and the name
// of an image resource to look for.
[ToolboxBitmap(typeof(MyControl), "MyControlBitmap")]
class MyControl : UserControl
{
}
| 注意: |
|---|
对于自动生成的控件和组件,位图将不出现在工具箱中。若要查看位图,请使用“选择工具箱项”对话框重新加载控件。 |