static public int MeasureDisplayStringWidth(Graphics graphics, string text,
Font font)
{
System.Drawing.StringFormat format = new System.Drawing.StringFormat ();
System.Drawing.RectangleF rect = new System.Drawing.RectangleF(0, 0,
1000, 1000);
System.Drawing.CharacterRange[] ranges =
{ new System.Drawing.CharacterRange(0,
text.Length)
System.Drawing.Region[] regions = new System.Drawing.Region[1];
format.SetMeasurableCharacterRanges (ranges);
regions = graphics.MeasureCharacterRanges (text, font, rect, format);
rect = regions[0].GetBounds (graphics);
return (int)(rect.Right + 1.0f);
}
FONCTION MeasureDisplayStringWidht(Graphique est un "graphics",Texte est un "string", fonte est une "font")
System.Drawing.StringFormat format = new System.Drawing.StringFormat ();
System.Drawing.RectangleF rect = new System.Drawing.RectangleF(0, 0,
1000, 1000);
System.Drawing.CharacterRange[] ranges =
{ new System.Drawing.CharacterRange(0,
text.Length) };
System.Drawing.Region[] regions = new System.Drawing.Region[1];
format.SetMeasurableCharacterRanges (ranges);
regions = Graphics.MeasureCharacterRanges (text, Font, rect, format);
rect = regions[0].GetBounds (Graphics);
RETURN (int)(rect.Right + 1.0f);
Cette contribution était de : http://old.wdforge.org/newbb/viewtopic.php?forum=14&topic_id=3584&post_id=15090