20 August 2012

Resize TextBox in C#.net

Here, I gave a TextBox resize in C#.net.user can call this function in form load event.
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;
        }
}

No comments: