Microsoft Developer Network >
Forums Home
>
Visual Studio Express Editions Forums
>
Visual C# Express Edition
>
Resizing combobox in toolstrip with window?
Resizing combobox in toolstrip with window?
- I have the following code:
What I want to be able to do is resize my combobox as i resize the actual window of my program. The bigger the window gets, the bigger the combox gets. Vis-Versa.private void Ibrowser_Resize(object sender, EventArgs e) { //add resizing to cburl }
Would appreciate any help, thanks.
OMG, its Joe Ginley!
Answers
- Hi,
You can use the following code.
decimal comboFormWidthRatio = 0; private void Form5_Load(object sender, EventArgs e) { toolStripComboBox1.AutoSize = false; comboFormWidthRatio=Convert.ToDecimal(toolStripComboBox1.Width) / Convert.ToDecimal(this.Width); } private void Form5_SizeChanged(object sender, EventArgs e) { decimal newWidth=Convert.ToDecimal(this.Bounds.Width) * comboFormWidthRatio; toolStripComboBox1.Width = Convert.ToInt32(newWidth); }- Marked As Answer byJoeGinley Friday, November 06, 2009 12:06 PM
All Replies
- Hi,
You can use a logic like below.
int width = 0; private void Form8_ResizeBegin(object sender, EventArgs e) { width = this.Size.Width; } private void Form8_ResizeEnd(object sender, EventArgs e) { toolStripComboBox1.AutoSize = false; decimal newWidth=Convert.ToDecimal(toolStripComboBox1.Width) * (Convert.ToDecimal(this.Size.Width) / Convert.ToDecimal(this.width)); toolStripComboBox1.Width = Convert.ToInt32(newWidth); } - It works, but when i click maximize it will not resize the combobox. what could i do for that? Thanks!
OMG, its Joe Ginley! - Hi,
You can use the following code.
decimal comboFormWidthRatio = 0; private void Form5_Load(object sender, EventArgs e) { toolStripComboBox1.AutoSize = false; comboFormWidthRatio=Convert.ToDecimal(toolStripComboBox1.Width) / Convert.ToDecimal(this.Width); } private void Form5_SizeChanged(object sender, EventArgs e) { decimal newWidth=Convert.ToDecimal(this.Bounds.Width) * comboFormWidthRatio; toolStripComboBox1.Width = Convert.ToInt32(newWidth); }- Marked As Answer byJoeGinley Friday, November 06, 2009 12:06 PM
- This did not work, it seems that my combobox just completely leaves the window or form? Do i have to keep the other code you provided?
OMG, its Joe Ginley! - No you should just use the last one.
- Thanks, it worked!
OMG, its Joe Ginley!

