Graphics in C# (.NET)
c#, graphics, winforms
Solution
Use `g.MeasureString()` to get the width of a string in the grapic context.
// 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);
Problem
I use this code for drawing text in a panel: ``` Graphics g = panel1.CreateGraphics(); g.DrawString(...); ``` So I want to know what size the input text will be when rendered in the panel.