Wednesday, October 15, 2008

Add any custom controls or Windows Forms controls to a ToolStrip

When we are in need to put some custom controls or Windows Forms controls to a ToolStrip and we think that we only have the options gave to us from the ToolStrip control, we need the help of the ToolStripControlHost Class. This class Hosts custom controls or Windows Forms controls.

Declare a ToolStripControlHost field. In the constructor of the Windows form and after InitializeComponent();, create a new ToolStripControlHost with your required controller in the argument. Then add the ToolStripControlHost to your ToolStrip Items.

It's that easy!!

  
private ToolStripControlHost toolStripControlHost;

public WindowsFormConstructor()
{
InitializeComponent();
toolStripControlHost = new ToolStripControlHost(dateTimePicker1);
toolStrip1.Items.Add(toolStripControlHost);
}

0 comments: