Skip to content

Instantly share code, notes, and snippets.

@abhi1010
Created May 6, 2014 07:08
Show Gist options
  • Save abhi1010/f488949a5d79b6d86544 to your computer and use it in GitHub Desktop.
Save abhi1010/f488949a5d79b6d86544 to your computer and use it in GitHub Desktop.
Auto Resize a Label
public void Resize(Label label1)
{
Graphics g = this.CreateGraphics(); //gets the graphics based on the client area
SizeF size = g.MeasureString(str, label1.Font); //gets the size of the text which will be displayed
label1.Size = new Size((int)size.Width, label1.Size.Height); //sets the length of the label (same height)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment