1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
/// <summary>
/// Dessine verticalement le texte fournit sur un objet graphics avec les paramètres de texte spécifiés
/// </summary>
/// <param name="g">graphics sur lequel dessiner</param>
/// <param name="texte">string</param>
/// <param name="font">police de caractère</param>
/// <param name="couleur">couleur du texte</param>
/// <param name="clientRect">zone maximum ou placer le texte</param>
/// <param name="position">position sur la zone maximum, permet de centrer</param>
/// <returns>True si aucune erreur</returns>
/// <remarks></remarks>
public bool DrawTexteVertical(System.Drawing.Graphics g, string texte, System.Drawing.Font font, System.Drawing.Color couleur, System.Drawing.Rectangle clientRect, System.Drawing.ContentAlignment position)
{
try {
if (g == null) return false;
if (string.IsNullOrEmpty(texte)) return true;
System.Drawing.Size tailleChar = default(System.Drawing.Size);
int x = 0;
int y = 0;
y = clientRect.Y;
for (int i = 0; i <= texte.Length - 1; i++) {
tailleChar = System.Windows.Forms.TextRenderer.MeasureText(texte.Chars(i), font);
x = clientRect.X + clientRect.Width / 2 - tailleChar.Width / 2;
g.DrawString(texte.Chars(i), font, new System.Drawing.SolidBrush(couleur), x, y);
y += tailleChar.Height - 1;
}
return true;
}
catch (Exception ex) {
TraceErreur.Trace(ex, g, texte, font, couleur, clientRect, position);
return false;
}
} |
Partager