dotnetmonitor.com

 
Index
Previous
Next

 

The two avenues of customization covered here are custom ToolStripItems at design time and custom renderer custom ToolStrips at design time.

Custom ToolStripItems

Custom ToolStripItems can be created by extending existing ToolStripItems like ToolStripButton or ToolStripMenuItem this is very similar to extending any control. To get these showing at design time and add them to ToolStrips, use the following sample for guidance.

Sample: ToolStripItemDesignerAvailability

This sample shows how to get custom items in the dropdowns used at design time for strip controls. It requires same named bitmaps to be added to the project as embedded resources.

 

// this extends ToolStripButton

// note: visibility from base class preserved

public class myFirstToolStripButton : ToolStripButton { }

 

// this adds visibility into MenuStrip

// ToolStrip, ContextMenuStrip, StatusStrip also supported [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.MenuStrip | ToolStripItemDesignerAvailability.ToolStrip)]

public class myOtherToolStripButton : ToolStripButton { }

 

// this adds a custom bitmap

[ToolboxBitmap(typeof(myNextToolStripButton), "myNextToolStripButton.bmp")]

public class myNextToolStripButton : ToolStripButton { }

 

// this adds custom toolbox item attributes

[ToolboxItem(typeof(CustomControlToolboxItem))]

public class myLastToolStripButton : ToolStripButton { }

 

public class CustomControlToolboxItem : ToolboxItem

{

public CustomControlToolboxItem() { }

 

public override void Initialize(Type type)

{

base.Initialize(type);

this.DisplayName = "My Last ToolStrip Button";

this.Bitmap = new Bitmap(typeof(CustomControlToolboxItem), "myLastToolStripButton.bmp");

}}

 

Custom ToolStrips

Custom ToolStrips are automatically added to the toolbox as are other controls with Whidbeys new auto toolbox population. What might not be apparent is using a custom ToolStrip as a vehicle to show off your custom Renderer and/or colors at designtime. This is simply a design pattern thats been useful.

Sample: CustomToolStrip @ DesignTime

public class myToolStrip : ToolStrip

{

public myToolStrip()

{

Renderer = new myToolStripRenderer();

}

}

public class myToolStripRenderer : ToolStripProfessionalRenderer

{

public myToolStripRenderer()

: base(new myProfessionalColors())

{

}

}

public class myProfessionalColors : ProfessionalColorTable

{

public override Color ToolStripGradientBegin

{

get { return Color.HotPink; }

}

 

public override Color ToolStripGradientEnd

{

get { return Color.Salmon; }

}

 

public override Color ToolStripGradientMiddle

{

get { return Color.Orange; }

}

}

Painting
When should I use Paint/OnPaint and when should I override the ToolStripRenderer?
Do I need to worry about double buffering?
Parenting
Partial Trust
Usage