操作說明:為控制項提供工具箱點陣圖
如果您想要讓控制項的特殊圖示出現在 Visual Studio 的工具箱 中 ,您可以使用 來指定特定影像 ToolboxBitmapAttribute 。 此類別是一個「屬性」,一種您可以附加至其他類別的特殊類別。 如需屬性的詳細資訊,請參閱 Visual Basic 的屬性概觀 (Visual Basic) 或 C# 的屬性 (C#)。
ToolboxBitmapAttribute使用 ,您可以指定字串,指出 16 x 16 圖元點陣圖的路徑和檔案名。 將此點陣圖新增至 [工具箱],它會接著出現在您的控制項旁邊。 您也可以指定 Type ,在此情況下會載入與該類型相關聯的點陣圖。 如果您同時 Type 指定 和 字串,控制項會在包含 參數所指定型別的元件中,搜尋名稱為字串參數所 Type 指定的影像資源。
指定控制項的工具箱點陣圖
ToolboxBitmapAttribute將 新增至控制項的類別宣告,再新增至 visual Basic 關鍵字之前
Class
,以及 Visual C# 類別宣告的上方。' 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 { }
重建專案。
注意
點陣圖並不會針對自動產生的控制項和元件出現在工具箱中。 若要查看點陣圖,請使用 [選擇工具箱項目] 對話方塊,重新載入控制項。 如需詳細資訊,請參閱逐步解說:自動將自訂元件填入工具箱。
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應