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
 
 
 
 
 
TitleCreate fonts easily by using the Font constructor that uses a prototype in Visual Basic .NET
DescriptionThis example shows how to create fonts easily by using the Font constructor that uses a prototype in Visual Basic .NET.
KeywordsFont, create font, font prototype, VB.NET
CategoriesGraphics, VB.NET
 
Thanks to Gary Winey.

The Font class provides a constructor that takes only two parameters: an existing font to use as a prototype and a set of font styles (bold, italic, etc.). This is the easiest way to create a new font.

This example reads some check boxes to see what styles to use. It then uses this version of the Font constructor and sets a Label control's Font property to the result.

 
Private Sub btnCreateFonts_Click(ByVal sender As _
    System.Object, ByVal e As System.EventArgs) Handles _
    btnCreateFonts.Click
    Dim font_style As FontStyle = FontStyle.Regular
    If chkBold.Checked Then font_style = font_style Or _
        FontStyle.Bold
    If chkItalic.Checked Then font_style = font_style Or _
        FontStyle.Italic
    If chkStrikeout.Checked Then font_style = font_style Or _
        FontStyle.Strikeout
    If chkUnderline.Checked Then font_style = font_style Or _
        FontStyle.Underline

    lblSample.Font = New Font(Me.Font, font_style)
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated