9.5 Changing a Control s Toolbox Icon

 <  Day Day Up  >  

9.5 Changing a Control's Toolbox Icon

You want to create a custom icon that is shown for your control within the Visual Studio .NET IDE toolbox.


Technique

Create a bitmap file that is 16 x 16. You can embed this bitmap within the assembly to free you from having to deploy it by choosing Project, Add Existing Item and selecting the bitmap file. To associate the bitmap file with your control, apply the ToolboxBitmap attribute to your control's class declaration. The first parameter to this attribute is a reference to the type of your control, which you can retrieve by using the typeof keyword. The second parameter is the name of the bitmap file:

 
 [     DefaultProperty("Percentage"),     ToolboxBitmap(typeof(TemperatureGauge3), "ToolboxIcon.bmp") ] public class TemperatureGauge3 : System.Windows.Forms.Control { ... } 

Comments

As a control author, you should strive to make your control look as professional as possible if you plan to allow other developers to use it. By default, when you create a control within Visual Studio, it receives a default icon.

Changing that icon is a trivial matter, as demonstrated earlier, but doing so allows you to distinguish it from other controls as well as give users a quick visual indication of what the control is. This step is especially important for users who turn off the text labels in the toolbox by right-clicking and unselecting the List View menu item. In that case, all that appears is an icon for each control, which is all the more reason to create an effective and informative toolbox bitmap for your control.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net