public MeasureString ( string text, Font font ) : SizeF | ||
text | string | |
font | Font | |
return | SizeF |
string text = "Hello World"; Font font = new Font("Arial", 12, FontStyle.Regular); SizeF size = graphics.MeasureString(text, font);
string text = "C# Graphics"; Font font = new Font("Times New Roman", 16, FontStyle.Bold); PointF point = new PointF(10, 10); SizeF size = graphics.MeasureString(text, font, point, StringFormat.GenericDefault);In this example, the MeasureString method is used to measure the size of the string "C# Graphics" using the Times New Roman font with a font size of 16 and bold style. The string is drawn at the point (10,10) and the method returns a SizeF object that contains the width and height of the drawn string in pixels. The MeasureString method is part of the System.Drawing package library in C#.