title: C# - Set Height of ComboBox
body: <p>I want to set the height of a <code>ComboBox</code> (from the Windows Forms <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.aspx" rel="nofollow">Control</a>s) to <strong>X</strong> <em>during runtime</em>. </p>
  
  <p>I have </p>
  
  <ul>
  <li>the <code>DrawMode</code> Property set to <code>OwnerDrawVariable</code>, to specify that the
  items are drawn manually;</li>
  <li>the <code>IntegralHeight</code> Property set to false, to avoid the <code>Control</code> from automatically resizing itself;</li>
  <li>the <code>ItemHeight</code> Property of the <code>ComboBox</code> also set to <strong>X</strong>.</li>
  </ul>
  
  <p>I've also overriden the <code>DrawItem</code> and <code>MeasureItem</code> events for the comboBox's items (see code below)</p>
  
  <p>However, <strong>setting the <code>Height</code> of the ComboBox at runtime only works if the <code>DropDownStyle</code> is set to <code>Simple</code>.</strong></p>
  
  <p>I do this both ways, programmatically (modifying the <code>ComboBox</code>'s <code>Height</code> or <code>Size</code>) property, and using a <code>PropertyGrid</code> Control which I have on my App.</p>
  
  <p>When I set the height of a <code>DropDown</code> or <code>DropDownList</code> <code>ComboBox</code>, I noticed that Windows automatically changes its height to another value: <strong>Y</strong> (which, after some debugging I noticed to be <strong>X + 6</strong> for some reason).</p>
  
  <p>What am I missing? Why does this happen?</p>
  
  <p>Here is the code from the handlers:</p>
  
  <pre><code>private void DrawItemHandler(object sender, DrawItemEventArgs e)
  {
    //Create a new font to write the item
    Font ComboItemFont = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular);
  
    e.DrawBackground();
    e.DrawFocusRectangle();
  
    //Write the item's value
    e.Graphics.DrawString(((ComboBox) sender).Items[e.Index].ToString(),
                          ComboItemFont,
                          new SolidBrush(Color.Black),
                          e.Bounds);
  
    //Update the source's font to match the current font
    ((Control) sender).Font = ComboItemFont;
  }
  
  private void MeasureItemHandler(object sender, MeasureItemEventArgs e)
  {
       //Do nothing
  }
  </code></pre>