方法: コントロールのツールボックス ビットマップを指定する
Visual Studio の ツールボックス にコントロールの特別なアイコンを表示する場合は、ToolboxBitmapAttributeを使用して特定のイメージを指定できます。 このクラスは 属性であり、他のクラスにアタッチできる特別な種類のクラスです。 属性の詳細については、「属性の概要 (Visual Basic) for Visual Basic」または「属性 (C#) for C#」を参照してください。
ToolboxBitmapAttributeを使用すると、16 x 16 ピクセル ビットマップのパスとファイル名を示す文字列を指定できます。 このビットマップは、ツールボックスに追加されると、コントロールの横に表示されます。 Typeを指定することもできます。この場合、その型に関連付けられているビットマップが読み込まれます。 Type と文字列の両方を指定した場合、コントロールは、Type パラメーターで指定された型を含むアセンブリ内の文字列パラメーターで指定された名前を持つイメージ リソースを検索します。
コントロールのツールボックス ビットマップを指定するには
visual Basic の
Class
キーワードの前、および Visual C# のクラス宣言の上に、コントロールのクラス宣言に ToolboxBitmapAttribute を追加します。' Specifies the bitmap associated with the Button type. <ToolboxBitmap(GetType(Button))> Class MyControl1 ' Specifies a bitmap file. End Class <ToolboxBitmap("C:\Documents and Settings\Joe\MyPics\myImage.bmp")> _ Class MyControl2 End Class ' Specifies a type that indicates the assembly to search, and the name ' of an image resource to look for. <ToolboxBitmap(GetType(MyControl), "MyControlBitmap")> Class MyControl End Class
// 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 { }
プロジェクトをリビルドします。
手記
自動生成されたコントロールとコンポーネントのビットマップはツールボックスに表示されません。 ビットマップを表示するには、[ツールボックス項目の選択] ダイアログ ボックス 使用してコントロール 再読み込みします。 詳細については、「チュートリアル: カスタム コンポーネントを使用してツールボックスを自動的に設定する」を参照してください。
関連項目
.NET Desktop feedback