Demonstration
The source.zip file for this article contains a demonstration program that shows the various text transforms that I’ve covered here. The program works by defining a reference to a global output bitmap:
private Bitmap bmp;
In the Form_Load event procedure, the bitmap is created, equal in size to the screen, and painted white. In addition, the display message is defined:
bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); //Paint the bitmap white. Graphics g = Graphics.FromImage(bmp); g.Clear(Color.White); g.Dispose(); msg = "Text Transforms!";
In the form’s Paint event procedure, the bitmap is drawn to the form’s display surface:
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { if (bmp != null) e.Graphics.DrawImage(bmp, 0, 0); }
The actual transforms are created and applied in the procedures for the program’s various menu commands. For example, here’s the procedure for the horizontal shear command:
private void menuItem3_Click(object sender, System.EventArgs e) { //Horizontal stretch. Graphics g = Graphics.FromImage(bmp); g.Clear(Color.White); g.ScaleTransform(2.0F, 1.0F); g.DrawString(msg, f, Brushes.Black, 10, 50); this.Refresh(); this.Text = "Horizontal stretch"; g.Dispose(); }
You can start with this program and then modify it to learn more about transforms and text. I was quite impressed with how easy .NET can create special text effects, and I think you’ll agree with me.