Created
April 23, 2023 11:11
-
-
Save LGM-AdrianHum/d1c9e6e611e930a62a1d649a4bcdcc06 to your computer and use it in GitHub Desktop.
Measure String Size for Given Font
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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