String Rectangle

image_pdfimage_print
   
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form {

    protected override void OnPaint(PaintEventArgs e) {
    Graphics g = e.Graphics;
    g.FillRectangle(Brushes.White, this.ClientRectangle);

    String s = "AAAAAAAAAA";
    StringFormat sf = new StringFormat(StringFormatFlags.DirectionVertical);
    Font f = new Font("Times New Roman", 14);
    SizeF sizef = g.MeasureString(s, f, Int32.MaxValue, sf);

    RectangleF rf = new RectangleF(20, 20, sizef.Width, sizef.Height);
    g.DrawRectangle(Pens.Black, rf.Left, rf.Top, rf.Width, rf.Height);
    g.DrawString(s, f, Brushes.Black, rf, sf);

    f.Dispose();
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}

    


This entry was posted in 2D Graphics. Bookmark the permalink.