Skip to content

Instantly share code, notes, and snippets.

@LGM-AdrianHum
Created April 23, 2023 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LGM-AdrianHum/d1c9e6e611e930a62a1d649a4bcdcc06 to your computer and use it in GitHub Desktop.
Save LGM-AdrianHum/d1c9e6e611e930a62a1d649a4bcdcc06 to your computer and use it in GitHub Desktop.
Measure String Size for Given Font
private float getTextSize(string text)
{
Font font = new Font("Courier New", 10.0F);
Image fakeImage = new Bitmap(1, 1);
Graphics graphics = Graphics.FromImage(fakeImage);
SizeF size = graphics.MeasureString(text, font);
return size.Width;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment