Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDraw hollow text in Visual Basic .NET
DescriptionThis example shows how to draw hollow text in Visual Basic .NET.
Keywordshollow text, GraphicsPath, path, text, Visual Basic .NET, VB.NET
CategoriesGraphics
 

When the form loads, it sets ResizeRedraw to true so the form repaints itself whenever it is resized.

 
' Redraw on resize.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    Me.ResizeRedraw = True
End Sub
 
The form's Paint event handler draws the hollow text.
 
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    ' Make things smoother.
    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias

    ' Create the text path.
    Dim path As New GraphicsPath(FillMode.Alternate)

    ' Draw text using a StringFormat to center it on the
    ' form.
    Using font_family As New FontFamily("Times New Roman")
        Using sf As New StringFormat()
            sf.Alignment = StringAlignment.Center
            sf.LineAlignment = StringAlignment.Center
            path.AddString("Hollow Text", font_family, _
                CInt(FontStyle.Bold), 100, _
                Me.ClientRectangle, sf)
        End Using
    End Using

    ' Fill and draw the path.
    e.Graphics.FillPath(Brushes.Blue, path)
    Using pen As New Pen(Color.Black, 3)
        e.Graphics.DrawPath(pen, path)
    End Using
End Sub
 
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.

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated