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
|
private void buttonEnvoyer_Click(object sender, EventArgs e)
{
Graphics g = label1.CreateGraphics();
g.RotateTransform(45);
Rectangle rec = new Rectangle( 0, 0, 80, 100);
DrawTexteVertical(g, "ok mémé", new Font("Verdana", 40), Color.Black, rec , ContentAlignment.MiddleCenter );
}
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;
string txt; //SA +
y = clientRect.Y;
for (int i = 0; i <= texte.Length - 1; i++) {
txt = texte[i].ToString(); //SA +
tailleChar = System.Windows.Forms.TextRenderer.MeasureText(txt, font);
x = clientRect.X + clientRect.Width / 2 - tailleChar.Width / 2;
g.DrawString(txt, 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); SA -
return false;
}
} |
Partager