Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Controls that you create always receive a generic icon for the Toolbox window in Visual Studio. However, when you change the icon, it adds a sense of professionalism to your control, and makes it stand out in the toolbox. This article teaches you how to set the icon for your control.
Bitmap icon
Icons for the Toolbox window in Visual Studio must conform to certain standards, otherwise they're ignored or are displayed incorrectly.
- Size: Icons for a control must be a 16x16 bitmap image.
- File type: The icon can be either a Bitmap (.bmp) or a Windows Icon (.ico) file.
- Transparency: The magenta color (RGB:
255,0,255
, Hex:0xFF00FF
) is rendered transparent. - Themes: Visual Studio has multiple themes, but each theme is considered either dark or light. Your icon should be designed for the light theme. When Visual Studio uses a dark theme, the dark and light colors in the icon are automatically inverted.
How to assign an icon
Icons are assigned to a control with the ToolboxBitmapAttribute attribute. For more information about attributes, see Attributes (C#) or Attributes overview (Visual Basic).
Tip
You can download a sample icon from GitHub.
The attribute is set on the control's class, and has three different constructors:
ToolboxBitmapAttribute(Type)—This constructor takes a single type reference, and from that type, tries to find an embedded resource to use as the icon.
The type's FullName is used to look up an embedded resource in the assembly of that type, using the following format:
{project-name}.{namespace-path}.{type-name}{.bmp|.ico}
. For example, if the typeMyProject.MyNamespace.CompassRose
is referenced, the attribute looks for an embedded resource namedMyProject.MyNamespace.CompassRose.bmp
orMyProject.MyNamespace.CompassRose.ico
.// Looks for a CompassRose.bmp or CompassRose.ico embedded resource in the // same namespace as the CompassRose type. [ToolboxBitmap(typeof(CompassRose))] public partial class CompassRose : UserControl { // Code for the control }
' Looks for a CompassRose.bmp or CompassRose.ico embedded resource in the ' same namespace as the CompassRose type. <ToolboxBitmap(GetType(CompassRose))> Public Class CompassRose ' Code for the control End Class
ToolboxBitmapAttribute(Type, String)—This constructor takes two parameters. The first parameter is a type, and the second is the namespace and name of the embedded resource in the assembly of that type.
// Loads the icon from the WinFormsApp1.Resources.CompassRose.bmp resource // in the assembly containing the type CompassRose [ToolboxBitmap(typeof(CompassRose), "WinFormsApp1.Resources.CompassRose.bmp")] public partial class CompassRose : UserControl { // Code for the control }
' Loads the icon from the WinFormsApp1.Resources.CompassRose.bmp resource ' in the assembly containing the type CompassRose <ToolboxBitmap(GetType(CompassRose), "WinFormsApp1.Resources.CompassRose.bmp")> Public Class CompassRose ' Code for the control End Class
ToolboxBitmapAttribute(String)—This constructor takes a single string parameter, the absolute path to the icon file.
// Loads the icon from a file on disk [ToolboxBitmap(@"C:\Files\Resources\MyIcon.bmp")] public partial class CompassRose : UserControl { // Code for the control }
' Loads the icon from a file on disk <ToolboxBitmap("C:\Files\Resources\MyIcon.bmp")> Public Class CompassRose ' Code for the control End Class
.NET Desktop feedback