Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to calculate string width in pixels
Message
From
20/04/2007 17:46:31
 
 
To
All
General information
Forum:
ASP.NET
Category:
Forms
Title:
How to calculate string width in pixels
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01218525
Message ID:
01218525
Views:
58
I created RDL file containing TextBox with constant text.
I used the following code to find TextBox tag value.
However textbox width is too large.

How to find exact width of string for given string ?
float MeasureString(string stringToPaint, string fontName, int fontSize) {

 Font font = new Font(fontName, fontSize, FontStyle.Regular);

 // Set TextFormatFlags to no padding so strings are drawn together.
 TextFormatFlags flags = TextFormatFlags.NoPadding | 
TextFormatFlags.NoPrefix;

 // Declare a proposed size with dimensions set to the maximum integer 
value.
 Size proposedSize = new Size(int.MaxValue, int.MaxValue);

 Size size = TextRenderer.MeasureText( stringToPaint,
       font, proposedSize, flags);
 return size.Width;
}
Andrus
Reply
Map
View

Click here to load this message in the networking platform