Measure Width of String in Pixels |
|
|
|
Written by Zack MIlls
|
Monday, 21 December 2009 13:02 |
Measure Width of String in Pixels
public static int mGetStringLength(string sString, string sFont, float iFontSize)
{
int iRet = 0;
try
{
Font font = new Font(sFont, iFontSize);
Bitmap bmp = new Bitmap(1, 1);
Graphics g = Graphics.FromImage(bmp);
int width = (int)g.MeasureString(sString, font).Width;
iRet = width;
g.Dispose();
}
catch { }
return iRet;
}
|