How to get char width and height
Hello everybody,
I need to display string which may be in different fonts and different sized. For positioning, I need to get the width of height of one character in pixels. If I have font name, font size etc. How can I calculate width and height of that particular character.
Thanks
Re: How to get char width and height
Code:
System.Drawing.Graphics myGraphics = Graphics.FromHwnd(System.IntPtr.Zero); //new graphics object
System.Drawing.SizeF mySize = myGraphics.MeasureString(myLabel.Text,myLabel.Font); //get the size of the text property
myLabel.Width = (int)mySize.Width +1;
a small Sample I used some time ago!
Hope that helps!
Stephan