Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to calculate string width in pixels
Message
De
20/04/2007 17:46:31
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
How to calculate string width in pixels
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01218525
Message ID:
01218525
Vues:
57
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
Répondre
Fil
Voir

Click here to load this message in the networking platform