The form's Paint event handler draws the hollow text.
private void Form1_Paint(object sender, PaintEventArgs e) { // Make things smoother. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
// Create the text path. GraphicsPath path = new GraphicsPath(FillMode.Alternate);
// Draw text using a StringFormat to center it on the form. using (FontFamily font_family = new FontFamily("Times New Roman")) { using (StringFormat sf = new StringFormat()) { sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; path.AddString("Hollow Text", font_family, (int)FontStyle.Bold, 100, this.ClientRectangle, sf); } }
// Fill and draw the path. e.Graphics.FillPath(Brushes.Blue, path); using (Pen pen = new Pen(Color.Black, 3)) { e.Graphics.DrawPath(pen, path); } }
The code starts by setting SmoothingMode to AntiAlias to get smoother curves.
Next the form makes a GraphicsPath object and adds text to it. It uses a StringFormat object to center the text on the form's client area.
The code then fills the GraphicsPath with a blue brush and then draws its outline with a thick black pen.
Comments