Ask a questionAsk a question
 

AnswerResizing combobox in toolstrip with window?

  • Thursday, November 05, 2009 4:47 AMJoeGinley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I have the following code:

    private void Ibrowser_Resize(object sender, EventArgs e)
            {
                //add resizing to cburl
            }
    
    
    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.

    Would appreciate any help, thanks.
    OMG, its Joe Ginley!

Answers

  • Thursday, November 05, 2009 8:45 PMTamer OzMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    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

  • Thursday, November 05, 2009 7:16 AMTamer OzMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    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);
                
            }
    
  • Thursday, November 05, 2009 8:34 PMJoeGinley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    It works, but when i click maximize it will not resize the combobox. what could i do for that? Thanks!
    OMG, its Joe Ginley!
  • Thursday, November 05, 2009 8:45 PMTamer OzMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    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
    •  
  • Friday, November 06, 2009 1:25 AMJoeGinley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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!
  • Friday, November 06, 2009 3:22 AMTamer OzMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    No you should just use the last one.
  • Friday, November 06, 2009 12:06 PMJoeGinley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks, it worked!
    OMG, its Joe Ginley!