Skip to content

Instantly share code, notes, and snippets.

@abhi1010
Created May 6, 2014 07:07
Show Gist options
  • Save abhi1010/e8390c5868a86998a7d5 to your computer and use it in GitHub Desktop.
Save abhi1010/e8390c5868a86998a7d5 to your computer and use it in GitHub Desktop.
Dynamically Resize Label
public void Resize(Label label1)
{
Graphics g = Graphics.FromHwnd(this.Handle); //gets the graphics form the form
SizeF size = g.MeasureString(label1.Text, 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