Text direction (Matrix Rotate) : Matrix « 2D Graphics « C# / C Sharp






Text direction (Matrix Rotate)

  
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using System.Drawing.Drawing2D;

public class Form1 : System.Windows.Forms.Form {
    [STAThread]
    static void Main() {
        Application.Run(new Form1());
    }
    protected override void OnPaint(PaintEventArgs e) {
        Graphics g = CreateGraphics();
        string txt = "HELLO";
        float alpha = 45.0f;
        int fontSize = 24;
        Point center = new Point(90, 20);

        FontFamily ff = new FontFamily("Times New Roman");
        Font f = new Font(ff, fontSize, FontStyle.Regular);
        StringFormat sf = new StringFormat();
        sf.FormatFlags = StringFormatFlags.DirectionVertical;
        g.DrawString(txt, f, new SolidBrush(Color.Blue), center, sf);

        g.TranslateTransform(center.X, center.Y);
        g.DrawEllipse(Pens.Magenta, new Rectangle(0, 0, 1, 1));

        GraphicsPath gp = new GraphicsPath();
        gp.AddString(txt, ff, (int)FontStyle.Bold, fontSize + 4, new Point(0, 0), sf);
        Matrix m = new Matrix();
        m.Rotate(alpha);
        gp.Transform(m);
        g.DrawPath(Pens.Red, gp);

        g.RotateTransform(-alpha);
        g.DrawString(txt, f, new SolidBrush(Color.Black), 0, 0, sf);

        gp.Dispose(); g.Dispose(); m.Dispose();
    }
}

   
  








Related examples in the same category

1.new Matrix(0.707f, 0.707f, -0.707f, 0.707f, 0, 0)
2.Matrix DemoMatrix Demo
3.Matrix DrawMatrix Draw
4.Multiply two Matrixes
5.Matrix Util