Resize ComboBox in C#.net

Naraayanan
Posted by Naraayanan under C# category on | Points: 40 | Views : 4764
  private void cmbwidth(ComboBox cmb)
{
System.Drawing.Graphics g = cmb.CreateGraphics();
float maxwidth = 0f;
foreach (object o in cmb.Items)
{
float w = g.MeasureString(o.ToString(), cmb.Font).Width;
if (w > maxwidth)
maxwidth = w;
}
g.Dispose();
cmb.Width = (int)maxwidth + 20;

}

Comments or Responses

Login to post response