Get width of System.Drawing.Font?

I use .Net tools to create a 2D drawing. System.Drawing.Font uses GetHeight() , which returns the height in pixels. I am missing GetWidth() to get the width! What should i use?

+4
source share
2 answers

Use Graphics.MeasureString Method (String, Font) :

Eg.

  // Set up string. string measureString = "Measure String"; Font stringFont = new Font("Arial", 16); // Measure string. SizeF stringSize = new SizeF(); stringSize = e.Graphics.MeasureString(measureString, stringFont); // This will give you string width, from which you can calculate further double width = stringSize.Width 
+8
source

What is the width? GetHeight returns the distance between the baselines of two lines of text, which is a property of the font itself. But the width depends on what you are going to write.

If you know exactly what you want to write, try the Graphics.MeasureString methods.

+4
source

Source: https://habr.com/ru/post/1444569/


All Articles