How to automatically resize toolstripcombobox when form is resized?
Hi!
I have a combo box on a toolstrip - toolstripcombobox - how can I automatically resize the combobox when the form is resized?
Matt
Hi!
I have a combo box on a toolstrip - toolstripcombobox - how can I automatically resize the combobox when the form is resized?
Matt
One way of doing it would be to add an event handler into the Form's Resize event.
At that stage you know that you are resizing the Form so you need to resize the combobox too.
Jero
This should do it:
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
ToolStripComboBox1.Width = this.Width / 2;
}
Put that in your Form.
Edit:
Sorry I forgot to give a description. When the Form is reasized for any reason, it will call the Resize event which will get into the function above. The code above thensets the width of ToolStripCombobox1 to the half the form's width.
You can see the combobox resizing when you drag the corner of the form but once you stop, the combobox is back in place?
Matt
All you need to do is to modify the event I posted earlier on.
protected override void ToolStrip1_Resize(Object Sender, EventArgs e)
{
base.OnResize(e);
ToolStripComboBox1.Width = ToolStripComboBox1.Parent.Width - 10;
}
Note that now the combo box has its width set relative to it's parent which is the toolstrip.
Or you could specify the toolstrip explicitly:
ToolStripComboBox1.Width = ToolStrip1.Width - 10;
Then just wire the event up to the toolstrip resize event
ToolStrip1.Resize += new EventHandler(this.Toolstrip1_Resize);