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 text that's filled with smaller text in Visual Basic .NET
DescriptionThis example shows how to draw text that's filled with smaller text in Visual Basic .NET.
Keywordshollow text, GraphicsPath, path, text, Visual Basic .NET, VB.NET
CategoriesGraphics
 

This program is very similar to the example Draw hollow text in Visual Basic .NET. See that example for most of the details.

The big difference between the two programs is the brush they use to fill the large text. This example uses the following code.

 
' Make a bitmap containing the brush's text.
Using small_font As New Font("Times New Roman", 8)
    ' See how big the text will be.
    Dim text_size As SizeF = _
        e.Graphics.MeasureString("Text", small_font)

    ' Make a Bitmap to hold the text.
    Dim bm As New Bitmap( _
        CInt(2 * text_size.Width), _
        CInt(2 * text_size.Height))
    Using gr As Graphics = Graphics.FromImage(bm)
        gr.Clear(Color.LightBlue)
        gr.DrawString("Text", small_font, Brushes.Red, 0, 0)
        gr.DrawString("Text", small_font, Brushes.Green, _
            text_size.Width, 0)
        gr.DrawString("Text", small_font, Brushes.Blue, _
            -text_size.Width / 2, text_size.Height)
        gr.DrawString("Text", small_font, _
            Brushes.DarkOrange, text_size.Width / 2, _
            text_size.Height)
        gr.DrawString("Text", small_font, Brushes.Blue, _
            1.5F * text_size.Width, text_size.Height)

        ' Fill the path with the brush.
        Using br As New TextureBrush(bm)
            e.Graphics.FillPath(br, path)
        End Using
    End Using

    ' Outline the path.
    Using pen As New Pen(Color.Black, 3)
        e.Graphics.DrawPath(pen, path)
    End Using
End Using
 
This code creates a small font. It uses the e.Graphics object's MeasureString method to see how big the string "Text" will be in this font. The program then makes a Bitmap twice as wide and tall as the string.

The code then clears the Bitmap and draws the string four times at different positions and in different colors on the Bitmap.

Finally the program uses the Bitmap to make a TextureBrush and fills the GraphicsPath containing the large text.

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