Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get string width in pixels, given the Font Object

Status
Not open for further replies.

VenkatRastapuram

Programmer
Oct 24, 2003
46
IN
Hello Sir,


I want to know the string width in pixels from the Font Object. so, Please tell me how to find the string width in pixels given the Font Object using .Net CompactFrameWork.


Regards,
R.Venkatesh
venkat@makelogicmldb.com
 
Image offScreenBmp;
offScreenBmp = new Bitmap(100, 900);
gdiSurface = Graphics.FromImage(offScreenBmp);


theFont = myFont;

public String TruncateByWidth(string myString, int EndWidth)
{
int count = 1;
SizeF MeasuredWidth = new SizeF();
while(MeasuredWidth.Width < EndWidth)
{
MeasuredWidth = gdiSurface.MeasureString(myString.Substring(0,count), theFont, 900);
count++;
}
string tmp;

tmp = myString.Substring(0, count);
tmp = tmp + &quot;..&quot;;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top