Resize TextBox in C#.net

Naraayanan
Posted by Naraayanan under C# category on | Points: 40 | Views : 2155
  private void txtWidth(TextBox txt)
{
System.Drawing.Graphics g = txt.CreateGraphics();
float maxwidth = 0f;
float w = g.MeasureString(txt.Text, txt.Font).Width;
if (w > maxwidth)
maxwidth = w;
g.Dispose();

txt.Width = (int)maxwidth;
}

Comments or Responses

Login to post response