String Width

  • Thread starter Thread starter Masood Naqvi
  • Start date Start date
M

Masood Naqvi

Guest
I have observed string width which I am getting in Windows10 is different from what I get in Windows7.

I am using following code:

public double CalculateTextLengthPixels(string msg, string FontName, decimal FontSize,string fontStyle, float DpiX)

{
//string msg = "Hello world!";
//string FontName = "Arial";
//decimal FontSize = 30;

double width = 0.0;
Font stringFont = new Font(FontName, (float)FontSize, (FontStyle)System.Enum.Parse(typeof(FontStyle),fontStyle), GraphicsUnit.Pixel);

using (Bitmap tempImage = new Bitmap(600, 600))
{
SizeF stringSize = Graphics.FromImage(tempImage).MeasureString(msg, stringFont);
width = stringSize.Width;
}
return DpiX * width/72;
}

Please tell me how to calculate string width in Windows7 accurately

Continue reading...
 
Back
Top