VB.Net Tutorial/2D Graphics

Материал из VB Эксперт
Перейти к: навигация, поиск

CellAscent, Descent, EmHeight, LineSpacing

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class MeasureString

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
       Dim textArea As SizeF
       Dim linePen As Pen
       Dim largeFont As Font
       Dim fontRatio As Single
       Dim ascentSize As Single
       Dim descentSize As Single
       Dim emSize As Single
       Dim cellHeight As Single
       Dim internalLeading As Single
       Dim externalLeading As Single
       e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
       largeFont = New Font("Times New Roman", 96, FontStyle.Regular)
       fontRatio = largeFont.Height / largeFont.FontFamily.GetLineSpacing(FontStyle.Regular)
       textArea = e.Graphics.MeasureString("AbcJgp", largeFont)
       e.Graphics.DrawString("AbcJgp", largeFont, Brushes.Black, 0, 0)
       linePen = New Pen(Color.Gray, 1)
       linePen.DashStyle = Drawing2D.DashStyle.Dash
       ascentSize = largeFont.FontFamily.GetCellAscent(FontStyle.Regular) * fontRatio
       descentSize = largeFont.FontFamily.GetCellDescent(FontStyle.Regular) * fontRatio
       emSize = largeFont.FontFamily.GetEmHeight(FontStyle.Regular) * fontRatio
       cellHeight = ascentSize + descentSize
       internalLeading = cellHeight - emSize
       externalLeading = (largeFont.FontFamily.GetLineSpacing(FontStyle.Regular) * fontRatio) - cellHeight
       e.Graphics.DrawLine(linePen, 0, 0, textArea.Width, 0)
       e.Graphics.DrawLine(linePen, 0, textArea.Height, textArea.Width, textArea.Height)
       e.Graphics.DrawLine(linePen, 0, ascentSize, textArea.Width, ascentSize)
       e.Graphics.DrawLine(linePen, 0, ascentSize + descentSize, textArea.Width, ascentSize + descentSize)
       linePen.Dispose()
       largeFont.Dispose()
       e.Graphics.ResetTransform()
   End Sub

End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.PictureBox1 = New System.Windows.Forms.PictureBox
       CType(Me.PictureBox1, System.ruponentModel.ISupportInitialize).BeginInit()
       Me.SuspendLayout()
       "
       "PictureBox1
       "
       Me.PictureBox1.BackColor = System.Drawing.Color.White
       Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
       Me.PictureBox1.Location = New System.Drawing.Point(8, 8)
       Me.PictureBox1.Name = "PictureBox1"
       Me.PictureBox1.Size = New System.Drawing.Size(550, 224)
       Me.PictureBox1.TabIndex = 0
       Me.PictureBox1.TabStop = False
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(600, 242)
       Me.Controls.Add(Me.PictureBox1)
       Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
       Me.MaximizeBox = False
       Me.Name = "Form1"
       Me.Text = "Measuring Text"
       CType(Me.PictureBox1, System.ruponentModel.ISupportInitialize).EndInit()
       Me.ResumeLayout(False)
   End Sub
   Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox

End Class</source>

Create and use FontStyle

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class FontStyleCreate

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim canvas As Graphics = e.Graphics
       
       Dim mainFont As Font
       Dim textStyle As New FontStyle
       textStyle = FontStyle.Regular
       mainFont = New Font("Arial", 40, textStyle)
       
       Dim brush1 As New SolidBrush(Color.DarkBlue)
       canvas.DrawString("www.vbex.ru",mainFont, brush1, 120, 70)        
       
       canvas = Nothing
   End Sub

End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(610, 328)
       Me.ResumeLayout(False)
   End Sub

End Class</source>

Create Font from Font

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class GDIObjectsCreateFontFromFont

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim canvas As Graphics = e.Graphics
       
       Dim brush1 As New SolidBrush(Color.DarkBlue)
       Dim font1 As New Font(Me.Font, FontStyle.Regular)
       
       canvas.DrawString("www.vbex.ru",font1, brush1, 120, 70)
       
       canvas = Nothing
   End Sub

End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(610, 328)
       Me.Name = "Form1"
       Me.Text = "Creating Graphics Objects (Color, Pen, Font, Brush)"
       Me.ResumeLayout(False)
   End Sub

End Class</source>

Create Font from ttf file

<source lang="vbnet">Imports System Imports System.Drawing Imports System.Collections Imports System.ruponentModel Imports System.Windows.Forms Imports System.Data Imports System.Drawing.Text public class CreateFontFromTTFFile

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class public class Form1

 Inherits System.Windows.Forms.Form
 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
       Dim g As Graphics = e.Graphics
       Dim pointF As New PointF(10, 20)
       Dim fontName As String
       Dim pfc As New PrivateFontCollection
       pfc.AddFontFile("tekhead.ttf")
       pfc.AddFontFile("DELUSION.TTF")
       pfc.AddFontFile("HEMIHEAD.TTF")
       pfc.AddFontFile("C:\WINNT\Fonts\Verdana.ttf")
       " Return all font families from the collection
       Dim fontFamilies As FontFamily() = pfc.Families
       Dim j As Integer
       While j < fontFamilies.Length
           fontName = fontFamilies(j).Name
           If fontFamilies(j).IsStyleAvailable(FontStyle.Italic) And fontFamilies(j).IsStyleAvailable(FontStyle.Bold) And fontFamilies(j).IsStyleAvailable(FontStyle.Underline) And fontFamilies(j).IsStyleAvailable(FontStyle.Strikeout) Then
               Dim newFont As New Font(fontName, 20, FontStyle.Italic Or FontStyle.Bold Or FontStyle.Underline, GraphicsUnit.Pixel)
               g.DrawString(fontName, newFont, New SolidBrush(Color.Red), pointF)
               pointF.Y += newFont.Height
           End If
       End While
       g.Dispose()
 End Sub
 Public Sub New()
  
   MyBase.New()
   Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
   Me.ClientSize = New System.Drawing.Size(292, 273)
   Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
 End Sub

End Class</source>

Create Font with font name, size and style

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class GDIObjectsCreateBrushFont

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim canvas As Graphics = e.Graphics
       
       Dim brush1 As New SolidBrush(Color.DarkBlue)
       Dim font1 As New Font("Arial", 24, FontStyle.Bold Or FontStyle.Italic)
       canvas.DrawString("www.vbex.ru",font1, brush1, 120, 70)
       
       canvas = Nothing
   End Sub

End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(610, 328)
       Me.Name = "Form1"
       Me.Text = "Creating Graphics Objects (Color, Pen, Font, Brush)"
       Me.ResumeLayout(False)
   End Sub

End Class</source>

Displaying font metric information

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System Imports System.Windows.Forms Imports System.Drawing.Text public class FontMetricsDisplay

  public Shared Sub Main
       Application.Run(New FrmFontMetrics)
  End Sub

End class

Public Class FrmFontMetrics

  Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
  Public Sub New()
     MyBase.New()
     "This call is required by the Windows Form Designer.
     InitializeComponent()
     "Add any initialization after the InitializeComponent() call
  End Sub
  "Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
     If disposing Then
        If Not (components Is Nothing) Then
           components.Dispose()
        End If
     End If
     MyBase.Dispose(disposing)
  End Sub
  "Required by the Windows Form Designer
  Private components As System.ruponentModel.Container
  "NOTE: The following procedure is required by the Windows Form Designer
  "It can be modified using the Windows Form Designer.  
  "Do not modify it using the code editor.
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
     "
     "frmFontMetrics
     "
     Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
     Me.ClientSize = New System.Drawing.Size(920, 253)
     Me.Name = "frmFontMetrics"
     Me.Text = "Metrics"
  End Sub
  1. End Region
  Protected Overrides Sub OnPaint( _
   ByVal paintEvent As PaintEventArgs)
     Dim graphicsObject As Graphics = paintEvent.Graphics
     Dim brush As SolidBrush = New SolidBrush(Color.Red)
     Dim pen As Pen = New Pen(brush, Convert.ToSingle(2.5))
     " Arial font metrics
     Dim arial As Font = New Font("Arial", 12)
     Dim family As FontFamily = arial.FontFamily
     Dim sanSerif As Font = New Font("Microsoft Sans Serif",14, FontStyle.Italic)
     pen.Color = brush.Color
     brush.Color = Color.DarkBlue
     graphicsObject.DrawString("Current Font: " & arial.ToString, arial, brush, 10, 10)
     Console.WriteLine("Ascent: " & family.GetCellAscent(FontStyle.Regular))
     Console.WriteLine("Descent: " & family.GetCellDescent(FontStyle.Regular))
     Console.WriteLine("Height: " & family.GetEmHeight(FontStyle.Regular))
     Console.WriteLine("Leading: " & family.GetLineSpacing(FontStyle.Regular))
     family = sanSerif.FontFamily
     Console.WriteLine("Current Font: " & sanSerif.ToString())
     Console.WriteLine("Ascent: " & family.GetCellAscent(FontStyle.Italic))
     Console.WriteLine("Descent: " & family.GetCellDescent(FontStyle.Italic))
     Console.WriteLine("Height: " & family.GetEmHeight(FontStyle.Italic))
     Console.WriteLine("Leading: " & family.GetLineSpacing(FontStyle.Italic))
  End Sub

End Class</source>

Draw Font Metrics

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms Imports System.Math public class DrawStringMetrics

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class public class Form1

 Inherits System.Windows.Forms.Form
 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
       Dim txt As String = "www.vbex.ru"
       Dim layout_rect As New RectangleF(0, 0, Me.ClientSize.Width , Me.ClientSize.Height)
       Dim string_format As New StringFormat
       string_format.LineAlignment = StringAlignment.Center
       string_format.Alignment = StringAlignment.Center
       Dim the_font As Font
       e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit
       the_font = New Font("Times New Roman", 80, FontStyle.Bold, GraphicsUnit.Pixel)
       MeasureCharacters(e.Graphics, the_font, txt, layout_rect, string_format)
   End Sub
   Public Sub MeasureCharacters(ByVal gr As Graphics, ByVal the_font As Font, ByVal txt As String, ByVal layout_rect As RectangleF, ByVal string_format As StringFormat)
       Dim character_ranges(txt.Length - 1) As CharacterRange
       For i As Integer = 0 To txt.Length - 1
           character_ranges(i) = New CharacterRange(i, 1)
       Next i
       string_format.SetMeasurableCharacterRanges(character_ranges)
       Dim character_regions() As Region = gr.MeasureCharacterRanges(txt, the_font, layout_rect, string_format)
       Dim em_height As Integer = the_font.FontFamily.GetEmHeight(FontStyle.Bold)
       Dim em_height_pix As Single = the_font.Size
       Dim design_to_pixels As Single = the_font.Size / em_height
       Dim ascent As Integer = the_font.FontFamily.GetCellAscent(FontStyle.Bold)
       Dim ascent_pix As Single = ascent * design_to_pixels
       Dim descent As Integer = the_font.FontFamily.GetCellDescent(FontStyle.Bold)
       Dim descent_pix As Single = descent * design_to_pixels
       Dim cell_height_pix As Single = ascent_pix + descent_pix
       Dim internal_leading_pix As Single = cell_height_pix - em_height_pix
       Dim line_spacing As Integer = the_font.FontFamily.GetLineSpacing(FontStyle.Bold)
       Dim line_spacing_pix As Single = line_spacing * design_to_pixels
       Dim external_leading_pix As Single = line_spacing_pix - cell_height_pix
       For Each rgn As Region In character_regions
           Dim character_bounds As RectangleF = rgn.GetBounds(gr)
           Dim character_rect As Rectangle = Rectangle.Round(character_bounds)
           gr.DrawRectangle(Pens.Black, character_rect)
           gr.DrawLine(Pens.White, character_rect.X, character_rect.Y + internal_leading_pix, character_rect.Right, character_rect.Y + internal_leading_pix)
           gr.DrawLine(Pens.Yellow, character_rect.X, character_rect.Y + ascent_pix, character_rect.Right, character_rect.Y + ascent_pix)
           gr.DrawLine(Pens.Orange, character_rect.X, character_rect.Y + ascent_pix + descent_pix, character_rect.Right, character_rect.Y + ascent_pix + descent_pix)
           gr.FillRectangle(Brushes.Red, character_rect.X, character_rect.Y + ascent_pix + descent_pix, character_rect.Width, external_leading_pix)
       Next rgn
       gr.DrawString(txt, the_font, Brushes.Black, layout_rect, string_format)
 End Sub
 Public Sub New()
  
   MyBase.New()
   Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
   Me.ClientSize = New System.Drawing.Size(292, 273)
   Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
 End Sub

End Class</source>

Font 3D

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class Font3D

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Inherits System.Windows.Forms.Form
   Public Sub New()
       MyBase.New()
       InitializeComponent()
   End Sub
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Private components As System.ruponentModel.IContainer
   Friend WithEvents TrackBar1 As System.Windows.Forms.TrackBar
   Friend WithEvents Panel1 As System.Windows.Forms.Panel
   Friend WithEvents Button1 As System.Windows.Forms.Button
   Friend WithEvents Button3 As System.Windows.Forms.Button
   Friend WithEvents Button2 As System.Windows.Forms.Button
   Friend WithEvents Button4 As System.Windows.Forms.Button
   Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
   Friend WithEvents Button5 As System.Windows.Forms.Button
   Friend WithEvents ColorDialog1 As System.Windows.Forms.ColorDialog
   Friend WithEvents FontDialog1 As System.Windows.Forms.FontDialog
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.TrackBar1 = New System.Windows.Forms.TrackBar
       Me.Panel1 = New System.Windows.Forms.Panel
       Me.Button1 = New System.Windows.Forms.Button
       Me.Button3 = New System.Windows.Forms.Button
       Me.Button2 = New System.Windows.Forms.Button
       Me.Button4 = New System.Windows.Forms.Button
       Me.TextBox1 = New System.Windows.Forms.TextBox
       Me.Button5 = New System.Windows.Forms.Button
       Me.ColorDialog1 = New System.Windows.Forms.ColorDialog
       Me.FontDialog1 = New System.Windows.Forms.FontDialog
       CType(Me.TrackBar1, System.ruponentModel.ISupportInitialize).BeginInit()
       Me.SuspendLayout()
       "
       "TrackBar1
       "
       Me.TrackBar1.Location = New System.Drawing.Point(48, 208)
       Me.TrackBar1.Maximum = 20
       Me.TrackBar1.Name = "TrackBar1"
       Me.TrackBar1.Size = New System.Drawing.Size(216, 45)
       Me.TrackBar1.TabIndex = 1
       "
       "Panel1
       "
       Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
       Me.Panel1.Location = New System.Drawing.Point(16, 16)
       Me.Panel1.Name = "Panel1"
       Me.Panel1.Size = New System.Drawing.Size(256, 112)
       Me.Panel1.TabIndex = 2
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(392, 266)
       Me.Controls.Add(Me.Panel1)
       Me.Controls.Add(Me.TrackBar1)
       CType(Me.TrackBar1, System.ruponentModel.ISupportInitialize).EndInit()
       Me.ResumeLayout(False)
   End Sub
   
   Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
       Dim color1, color2 As Color
       Dim TrackbarPos1, TrackbarPos2
       color1 = Color.Green
       color2 = Color.Black
       TrackbarPos1 = 0
       Dim a As Graphics = Panel1.CreateGraphics
       Dim b As New SolidBrush(color1)
       Dim c As New SolidBrush(color2)
       Dim d As New SolidBrush(Me.BackColor)
       Dim k As Integer
       a.FillRectangle(d, ClientRectangle)
       For k = TrackBar1.Value To 1 Step -1
           a.DrawString("3D Font", FontDialog1.Font, c, 20 + k, 20 - k)
       Next
       a.DrawString("3D Font", FontDialog1.Font, b, 20, 20)
   End Sub
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   End Sub

End Class</source>

Font Size

<source lang="vbnet">Imports System.Globalization Imports System.Text Imports System.Collections Imports System.ruponentModel Imports System.Data Imports System.Drawing Imports System.Drawing.Text Imports System Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class FontSizeDemo

  public Shared Sub Main
       Application.Run(New FontSizesForm)
  End Sub

End class

Public Class FontSizesForm

   Inherits System.Windows.Forms.Form
   Public Sub New()
       MyBase.New()
       InitializeComponent()
   End Sub
   Private components As System.ruponentModel.IContainer
   Friend WithEvents listBox1 As System.Windows.Forms.ListBox
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.listBox1 = New System.Windows.Forms.ListBox()
       Me.SuspendLayout()
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(560, 182)
       Me.Name = "FontSizesForm"
       Me.Text = "FontSizesForm"
       Me.ResumeLayout(False)
   End Sub
   Private Function GetPixelsFromPoints(ByVal points As Single, ByVal dpi As Single) As Single
       Return (dpi * points) / 72
   End Function
   Private Function GetInchesFromPoints(ByVal points As Single, ByVal dpi As Single) As Single
       Return GetPixelsFromPoints(points, dpi) / dpi
   End Function
   Private Function GetPixelsFromDesignUnits(ByVal designUnits As Single, ByVal font As Font, ByVal dpi As Single) As Single
       Dim scale As Single = GetPixelsFromPoints(font.Size, dpi) / font.FontFamily.GetEmHeight(font.Style)
       Return designUnits * scale
   End Function
   Private Function GetPointsFromPixels(ByVal pixels As Single, ByVal dpi As Single) As Single
       Return (pixels * 72) / dpi
   End Function
   Private Sub FontSizesForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim g As Graphics = Me.CreateGraphics()
       Console.WriteLine("Font.Name=                       {0}", Me.Font.Name)
       Console.WriteLine("Font.FontFamly.Name=             {0}", Me.Font.FontFamily.Name)
       Console.WriteLine("Font.Size=                       {0} {1}s (specified Unit)", Me.Font.Size, Me.Font.Unit.ToString())
       Console.WriteLine("Font.Height=                     {0} Pixels", Me.Font.Height)
       Console.WriteLine("Font.GetHeight=                  {0} Pixels", Me.Font.GetHeight(g))
       Console.WriteLine("Font.SizeInPoints=               {0} Points", Me.Font.SizeInPoints.ToString())
       Console.WriteLine("GetPixels(Font.SizeInPoints)=    {0} Pixels", GetPixelsFromPoints(Me.Font.SizeInPoints, g.DpiY))
       Console.WriteLine("GetInches(Font.SizeInPoints)=    {0} Inches", GetInchesFromPoints(Me.Font.SizeInPoints, g.DpiY))
       Console.WriteLine("Font.FontFamily.GetEmHeight=     {0} Design Units", Me.Font.FontFamily.GetEmHeight(FontStyle.Regular))
       Console.WriteLine("GetPixels(GetEmHeight)=          {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetEmHeight(Me.Font.Style), Me.Font, g.DpiY))
       Console.WriteLine("Font.FontFamily.GetLineSpacing=  {0} Design Units", Me.Font.FontFamily.GetLineSpacing(FontStyle.Regular))
       Console.WriteLine("GetPixels(GetLineSpacing)=       {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetLineSpacing(Me.Font.Style), Me.Font, g.DpiY))
       Console.WriteLine("Font.FontFamily.GetCellAscent=   {0} Design Units", Me.Font.FontFamily.GetCellAscent(FontStyle.Regular))
       Console.WriteLine("GetPixels(GetCellAscent)=        {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetCellAscent(Me.Font.Style), Me.Font, g.DpiY))
       Console.WriteLine("Font.FontFamily.GetCellDescent=  {0} Design Units", Me.Font.FontFamily.GetCellDescent(FontStyle.Regular))
       Console.WriteLine("GetPixels(GetCellDescent)=       {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetCellDescent(Me.Font.Style), Me.Font, g.DpiY))
       Console.WriteLine("Padding=                         {0} Design Units", Me.Font.FontFamily.GetLineSpacing(FontStyle.Regular) - (Me.Font.FontFamily.GetCellAscent(FontStyle.Regular) + Me.Font.FontFamily.GetCellDescent(FontStyle.Regular)))
       "Console.WriteLine("GetPixels(Padding)=              {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetLineSpacing(FontStyle.Regular) - (Me.Font.FontFamily.GetCellAscent(FontStyle.Regular) + Me.Font.FontFamily.GetCellDescent(FontStyle.Regular)), Me.Font, g.DpiY)))
   End Sub

End Class</source>

FontStyle.Bold Or FontStyle.Italic

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class GDIObjectsCreateBrushFont

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim canvas As Graphics = e.Graphics
       
       Dim brush1 As New SolidBrush(Color.DarkBlue)
       Dim font1 As New Font("Arial", 24, FontStyle.Bold Or FontStyle.Italic)
       canvas.DrawString("www.vbex.ru",font1, brush1, 120, 70)
       
       canvas = Nothing
   End Sub

End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(610, 328)
       Me.Name = "Form1"
       Me.Text = "Creating Graphics Objects (Color, Pen, Font, Brush)"
       Me.ResumeLayout(False)
   End Sub

End Class</source>

FontStyle.Bold Or FontStyle.Italic Or FontStyle.Underline Or FontStyle.Strikeout

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class FontStyleBoldItalicUnderlineStrikout

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim canvas As Graphics = e.Graphics
       
       Dim mainFont As Font
       Dim textStyle As New FontStyle
       textStyle = FontStyle.Regular
       textStyle = textStyle Or FontStyle.Bold
       textStyle = textStyle Or FontStyle.Italic Or FontStyle.Underline Or FontStyle.Strikeout
       mainFont = New Font("Arial", 40, textStyle)
       
       Dim brush1 As New SolidBrush(Color.DarkBlue)
       canvas.DrawString("www.vbex.ru",mainFont, brush1, 120, 70)        
       
       canvas = Nothing
   End Sub

End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(610, 328)
       Me.ResumeLayout(False)
   End Sub

End Class</source>

Get Font information

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class FontInfoFontDialog

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Inherits System.Windows.Forms.Form
   Dim FontDB As New FontDialog()
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents Button1 As System.Windows.Forms.Button
   Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.Button1 = New System.Windows.Forms.Button()
       Me.TextBox1 = New System.Windows.Forms.TextBox()
       Me.SuspendLayout()
       "
       "Button1
       "
       Me.Button1.Location = New System.Drawing.Point(104, 32)
       Me.Button1.Name = "Button1"
       Me.Button1.TabIndex = 0
       Me.Button1.Text = "Font Info"
       "
       "TextBox1
       "
       Me.TextBox1.Location = New System.Drawing.Point(20, 80)
       Me.TextBox1.Multiline = True
       Me.TextBox1.Name = "TextBox1"
       Me.TextBox1.Size = New System.Drawing.Size(250, 150)
       Me.TextBox1.TabIndex = 1
       Me.TextBox1.Text = ""
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(292, 273)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1, Me.Button1})
       Me.Name = "Form1"
       Me.Text = "FontInfo"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
       If (FontDB.ShowDialog() = DialogResult.OK) Then
           Dim CrLf As String = Chr(13) & Chr(10)
           TextBox1.Text = ""
           TextBox1.AppendText("Font Name: " & FontDB.Font.Name)
           TextBox1.AppendText(CrLf)
           TextBox1.AppendText("Bold: " & FontDB.Font.Bold)
           TextBox1.AppendText(CrLf)
           TextBox1.AppendText("Italic: " & FontDB.Font.Italic)
           TextBox1.AppendText(CrLf)
           TextBox1.AppendText("Size: " & FontDB.Font.Size)
           TextBox1.AppendText(CrLf)
           TextBox1.AppendText("Strikeout: " & FontDB.Font.Strikeout)
           TextBox1.AppendText(CrLf)
           TextBox1.AppendText("Underline: " & FontDB.Font.Underline)
           TextBox1.AppendText(CrLf)
       End If
   End Sub

End Class</source>

Set font name, size and style

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class FontStyleSizeName

  public Shared Sub Main
       Application.Run(New FrmFonts)
  End Sub

End class

Public Class FrmFonts

  Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
  Public Sub New()
     MyBase.New()
     "This call is required by the Windows Form Designer.
     InitializeComponent()
     "Add any initialization after the InitializeComponent() call
  End Sub
  "Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
     If disposing Then
        If Not (components Is Nothing) Then
           components.Dispose()
        End If
     End If
     MyBase.Dispose(disposing)
  End Sub
  "Required by the Windows Form Designer
  Private components As System.ruponentModel.Container
  "NOTE: The following procedure is required by the Windows Form Designer
  "It can be modified using the Windows Form Designer.  
  "Do not modify it using the code editor.
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
     "
     "frmFonts
     "
     Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
     Me.ClientSize = New System.Drawing.Size(496, 117)
     Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
     Me.Name = "frmFonts"
     Me.Text = "Fonts"
  End Sub
  1. End Region
  Protected Overrides Sub OnPaint( _
     ByVal paintEvent As PaintEventArgs)
     Dim graphicsObject As Graphics = paintEvent.Graphics
     Dim brush As SolidBrush = New SolidBrush(Color.DarkBlue)
     Dim style As FontStyle = FontStyle.Bold
     Dim arial As Font = New Font(New FontFamily("Arial"), 12, style)
     graphicsObject.DrawString(arial.Name & " 12 point bold.",arial, brush, 10, 10)
     style = FontStyle.Regular
     Dim timesNewRoman As Font = New Font("Times New Roman", 12, style)
     graphicsObject.DrawString(timesNewRoman.Name &" 12 point plain.", timesNewRoman, brush, 10, 30)
     style = FontStyle.Bold Or FontStyle.Italic
     Dim courierNew As Font = New Font("Courier New",16, style)
     graphicsObject.DrawString(courierNew.Name &" 16 point bold and italic.", courierNew, brush, 10, 54)
     style = FontStyle.Strikeout
     Dim tahoma As Font = New Font("Tahoma", 18, style)
     graphicsObject.DrawString(tahoma.Name &" 18 point strikeout.", tahoma, brush, 10, 75)
  End Sub

End Class</source>

Use CheckBox to control font

<source lang="vbnet">Imports System.Windows.Forms public class RadioButtonControlFont

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class

Public Class Form1

   Public mysize As Integer
   Public mybold As Boolean
   Public myItalic As Boolean
   Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
       CheckBox1.Checked = 1
   End Sub
   Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
       myItalic = Not myItalic
       TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Regular)
       If myItalic And mybold Then
           TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)
       ElseIf myItalic Then
           TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)
       ElseIf mybold Then
           TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)
       End If
   End Sub
   Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
   End Sub
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       mybold = False
       myItalic = False
       mysize = 25
   End Sub
   Private Sub RadioButton1_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
       mysize = 36
       TextBox1.Font = New System.Drawing.Font("", mysize)
   End Sub
   Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
       mysize = 25
       TextBox1.Font = New System.Drawing.Font("", mysize)
   End Sub
   Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
       mybold = Not mybold
       TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Regular)
       If myItalic And mybold Then
           TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)
       ElseIf myItalic Then
           TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)
       ElseIf mybold Then
           TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)
       End If
   End Sub

End Class <Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.CheckBox1 = New System.Windows.Forms.CheckBox
       Me.CheckBox2 = New System.Windows.Forms.CheckBox
       Me.GroupBox1 = New System.Windows.Forms.GroupBox
       Me.RadioButton1 = New System.Windows.Forms.RadioButton
       Me.RadioButton2 = New System.Windows.Forms.RadioButton
       Me.TextBox1 = New System.Windows.Forms.TextBox
       Me.GroupBox1.SuspendLayout()
       Me.SuspendLayout()
       "
       "CheckBox1
       "
       Me.CheckBox1.AutoSize = True
       Me.CheckBox1.Location = New System.Drawing.Point(230, 34)
       Me.CheckBox1.Name = "CheckBox1"
       Me.CheckBox1.Size = New System.Drawing.Size(48, 16)
       Me.CheckBox1.TabIndex = 1
       Me.CheckBox1.Text = "Italic"
       Me.CheckBox1.UseVisualStyleBackColor = True
       "
       "CheckBox2
       "
       Me.CheckBox2.AutoSize = True
       Me.CheckBox2.Location = New System.Drawing.Point(230, 56)
       Me.CheckBox2.Name = "CheckBox2"
       Me.CheckBox2.Size = New System.Drawing.Size(48, 16)
       Me.CheckBox2.TabIndex = 2
       Me.CheckBox2.Text = "Bold"
       Me.CheckBox2.UseVisualStyleBackColor = True
       "
       "GroupBox1
       "
       Me.GroupBox1.Controls.Add(Me.RadioButton2)
       Me.GroupBox1.Controls.Add(Me.RadioButton1)
       Me.GroupBox1.Location = New System.Drawing.Point(224, 85)
       Me.GroupBox1.Name = "GroupBox1"
       Me.GroupBox1.Size = New System.Drawing.Size(132, 77)
       Me.GroupBox1.TabIndex = 3
       Me.GroupBox1.TabStop = False
       Me.GroupBox1.Text = "Font size"
       "
       "RadioButton1
       "
       Me.RadioButton1.AutoSize = True
       Me.RadioButton1.Location = New System.Drawing.Point(6, 20)
       Me.RadioButton1.Name = "RadioButton1"
       Me.RadioButton1.Size = New System.Drawing.Size(59, 16)
       Me.RadioButton1.TabIndex = 1
       Me.RadioButton1.TabStop = True
       Me.RadioButton1.Text = "Larger font"
       Me.RadioButton1.UseVisualStyleBackColor = True
       "
       "RadioButton2
       "
       Me.RadioButton2.AutoSize = True
       Me.RadioButton2.Location = New System.Drawing.Point(6, 42)
       Me.RadioButton2.Name = "RadioButton2"
       Me.RadioButton2.Size = New System.Drawing.Size(59, 16)
       Me.RadioButton2.TabIndex = 2
       Me.RadioButton2.TabStop = True
       Me.RadioButton2.Text = "Smaller font"
       Me.RadioButton2.UseVisualStyleBackColor = True
       "
       "TextBox1
       "
       Me.TextBox1.Location = New System.Drawing.Point(12, 12)
       Me.TextBox1.Multiline = True
       Me.TextBox1.Name = "TextBox1"
       Me.TextBox1.Size = New System.Drawing.Size(195, 150)
       Me.TextBox1.TabIndex = 4
       Me.TextBox1.Text = "www.vbex.ru"
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(368, 174)
       Me.Controls.Add(Me.TextBox1)
       Me.Controls.Add(Me.GroupBox1)
       Me.Controls.Add(Me.CheckBox2)
       Me.Controls.Add(Me.CheckBox1)
       Me.Name = "Form1"
       Me.Text = "Form1"
       Me.GroupBox1.ResumeLayout(False)
       Me.GroupBox1.PerformLayout()
       Me.ResumeLayout(False)
       Me.PerformLayout()
   End Sub
   Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
   Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
   Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
   Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
   Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
   Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

End Class</source>

Use CheckBox to Set Font

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class UseCheckBoxRadioButtonSetFont

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Inherits System.Windows.Forms.Form
   Private LabelStyle As FontStyle
   Public Sub New()
       MyBase.New()
       InitializeComponent()
   End Sub
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Private components As System.ruponentModel.IContainer
   Friend WithEvents Label1 As System.Windows.Forms.Label
   Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
   Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
   Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
   Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
   Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
   Friend WithEvents RadioButton4 As System.Windows.Forms.RadioButton
   Friend WithEvents RadioButton5 As System.Windows.Forms.RadioButton
   Friend WithEvents RadioButton6 As System.Windows.Forms.RadioButton
   Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
   Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
   Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
   Friend WithEvents CheckBox3 As System.Windows.Forms.CheckBox
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.Label1 = New System.Windows.Forms.Label
       Me.GroupBox1 = New System.Windows.Forms.GroupBox
       Me.RadioButton1 = New System.Windows.Forms.RadioButton
       Me.RadioButton2 = New System.Windows.Forms.RadioButton
       Me.RadioButton3 = New System.Windows.Forms.RadioButton
       Me.GroupBox2 = New System.Windows.Forms.GroupBox
       Me.RadioButton4 = New System.Windows.Forms.RadioButton
       Me.RadioButton5 = New System.Windows.Forms.RadioButton
       Me.RadioButton6 = New System.Windows.Forms.RadioButton
       Me.GroupBox3 = New System.Windows.Forms.GroupBox
       Me.CheckBox1 = New System.Windows.Forms.CheckBox
       Me.CheckBox2 = New System.Windows.Forms.CheckBox
       Me.CheckBox3 = New System.Windows.Forms.CheckBox
       Me.GroupBox1.SuspendLayout()
       Me.GroupBox2.SuspendLayout()
       Me.GroupBox3.SuspendLayout()
       Me.SuspendLayout()
       "
       "Label1
       "
       Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
       Me.Label1.Location = New System.Drawing.Point(24, 16)
       Me.Label1.Name = "Label1"
       Me.Label1.Size = New System.Drawing.Size(288, 88)
       Me.Label1.TabIndex = 0
       Me.Label1.Text = "Visual Basic.NET"
       "
       "GroupBox1
       "
       Me.GroupBox1.Controls.Add(Me.RadioButton3)
       Me.GroupBox1.Controls.Add(Me.RadioButton2)
       Me.GroupBox1.Controls.Add(Me.RadioButton1)
       Me.GroupBox1.Location = New System.Drawing.Point(32, 136)
       Me.GroupBox1.Name = "GroupBox1"
       Me.GroupBox1.Size = New System.Drawing.Size(72, 120)
       Me.GroupBox1.TabIndex = 1
       Me.GroupBox1.TabStop = False
       Me.GroupBox1.Text = "Color"
       "
       "RadioButton1
       "
       Me.RadioButton1.Location = New System.Drawing.Point(8, 24)
       Me.RadioButton1.Name = "RadioButton1"
       Me.RadioButton1.Size = New System.Drawing.Size(56, 16)
       Me.RadioButton1.TabIndex = 0
       Me.RadioButton1.Text = "Red"
       "
       "RadioButton2
       "
       Me.RadioButton2.Location = New System.Drawing.Point(8, 48)
       Me.RadioButton2.Name = "RadioButton2"
       Me.RadioButton2.Size = New System.Drawing.Size(56, 16)
       Me.RadioButton2.TabIndex = 1
       Me.RadioButton2.Text = "Yellow"
       "
       "RadioButton3
       "
       Me.RadioButton3.Location = New System.Drawing.Point(8, 72)
       Me.RadioButton3.Name = "RadioButton3"
       Me.RadioButton3.Size = New System.Drawing.Size(56, 24)
       Me.RadioButton3.TabIndex = 2
       Me.RadioButton3.Text = "Green"
       "
       "GroupBox2
       "
       Me.GroupBox2.Controls.Add(Me.RadioButton6)
       Me.GroupBox2.Controls.Add(Me.RadioButton5)
       Me.GroupBox2.Controls.Add(Me.RadioButton4)
       Me.GroupBox2.Location = New System.Drawing.Point(128, 136)
       Me.GroupBox2.Name = "GroupBox2"
       Me.GroupBox2.Size = New System.Drawing.Size(80, 120)
       Me.GroupBox2.TabIndex = 2
       Me.GroupBox2.TabStop = False
       Me.GroupBox2.Text = "Font Size"
       "
       "RadioButton4
       "
       Me.RadioButton4.Location = New System.Drawing.Point(16, 24)
       Me.RadioButton4.Name = "RadioButton4"
       Me.RadioButton4.Size = New System.Drawing.Size(48, 16)
       Me.RadioButton4.TabIndex = 0
       Me.RadioButton4.Text = "10"
       "
       "RadioButton5
       "
       Me.RadioButton5.Location = New System.Drawing.Point(16, 48)
       Me.RadioButton5.Name = "RadioButton5"
       Me.RadioButton5.Size = New System.Drawing.Size(56, 24)
       Me.RadioButton5.TabIndex = 1
       Me.RadioButton5.Text = "20"
       "
       "RadioButton6
       "
       Me.RadioButton6.Location = New System.Drawing.Point(16, 80)
       Me.RadioButton6.Name = "RadioButton6"
       Me.RadioButton6.Size = New System.Drawing.Size(56, 24)
       Me.RadioButton6.TabIndex = 2
       Me.RadioButton6.Text = "30"
       "
       "GroupBox3
       "
       Me.GroupBox3.Controls.Add(Me.CheckBox3)
       Me.GroupBox3.Controls.Add(Me.CheckBox2)
       Me.GroupBox3.Controls.Add(Me.CheckBox1)
       Me.GroupBox3.Location = New System.Drawing.Point(224, 144)
       Me.GroupBox3.Name = "GroupBox3"
       Me.GroupBox3.Size = New System.Drawing.Size(88, 120)
       Me.GroupBox3.TabIndex = 3
       Me.GroupBox3.TabStop = False
       Me.GroupBox3.Text = "Other"
       "
       "CheckBox1
       "
       Me.CheckBox1.Location = New System.Drawing.Point(16, 16)
       Me.CheckBox1.Name = "CheckBox1"
       Me.CheckBox1.Size = New System.Drawing.Size(64, 24)
       Me.CheckBox1.TabIndex = 0
       Me.CheckBox1.Text = "Italic"
       "
       "CheckBox2
       "
       Me.CheckBox2.Location = New System.Drawing.Point(16, 48)
       Me.CheckBox2.Name = "CheckBox2"
       Me.CheckBox2.Size = New System.Drawing.Size(48, 24)
       Me.CheckBox2.TabIndex = 1
       Me.CheckBox2.Text = "Bold"
       "
       "CheckBox3
       "
       Me.CheckBox3.Location = New System.Drawing.Point(16, 80)
       Me.CheckBox3.Name = "CheckBox3"
       Me.CheckBox3.Size = New System.Drawing.Size(64, 24)
       Me.CheckBox3.TabIndex = 2
       Me.CheckBox3.Text = "Underline"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(328, 278)
       Me.Controls.Add(Me.GroupBox3)
       Me.Controls.Add(Me.GroupBox2)
       Me.Controls.Add(Me.GroupBox1)
       Me.Controls.Add(Me.Label1)
       Me.Name = "Form1"
       Me.Text = "Font Setting"
       Me.GroupBox1.ResumeLayout(False)
       Me.GroupBox2.ResumeLayout(False)
       Me.GroupBox3.ResumeLayout(False)
       Me.ResumeLayout(False)
   End Sub
   Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
       Label1.ForeColor = Color.Red
   End Sub
   Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
       Label1.ForeColor = Color.Yellow
   End Sub
   Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
       Label1.ForeColor = Color.Green
   End Sub
   Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
       Label1.Font = New Font(Label1.Font.FontFamily, 10)
   End Sub
   Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged
       Label1.Font = New Font(Label1.Font.FontFamily, 20)
   End Sub
   Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged
       Label1.Font = New Font(Label1.Font.FontFamily, 30)
   End Sub
   Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
       LabelStyle = LabelStyle Xor FontStyle.Italic
       Label1.Font = New Font(Label1.Font, LabelStyle)
   End Sub
   Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
       LabelStyle = LabelStyle Xor FontStyle.Bold
       Label1.Font = New Font(Label1.Font, LabelStyle)
   End Sub
   Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
       LabelStyle = LabelStyle Xor FontStyle.Underline
       Label1.Font = New Font(Label1.Font, LabelStyle)
   End Sub

End Class</source>

Use Or to add extra FontStyle.Bold

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class FontStyleOrAdding

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim canvas As Graphics = e.Graphics
       
       Dim mainFont As Font
       Dim textStyle As New FontStyle
       textStyle = FontStyle.Regular
       textStyle = textStyle Or FontStyle.Bold
       mainFont = New Font("Arial", 40, textStyle)
       
       Dim brush1 As New SolidBrush(Color.DarkBlue)
       canvas.DrawString("www.vbex.ru",mainFont, brush1, 120, 70)        
       
       canvas = Nothing
   End Sub

End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(610, 328)
       Me.ResumeLayout(False)
   End Sub

End Class</source>

Use RadioButton to control font

<source lang="vbnet">Imports System.Windows.Forms public class RadioButtonControlFont

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class

Public Class Form1

   Public mysize As Integer
   Public mybold As Boolean
   Public myItalic As Boolean
   Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
       CheckBox1.Checked = 1
   End Sub
   Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
       myItalic = Not myItalic
       TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Regular)
       If myItalic And mybold Then
           TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)
       ElseIf myItalic Then
           TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)
       ElseIf mybold Then
           TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)
       End If
   End Sub
   Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
   End Sub
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       mybold = False
       myItalic = False
       mysize = 25
   End Sub
   Private Sub RadioButton1_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
       mysize = 36
       TextBox1.Font = New System.Drawing.Font("", mysize)
   End Sub
   Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
       mysize = 25
       TextBox1.Font = New System.Drawing.Font("", mysize)
   End Sub
   Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
       mybold = Not mybold
       TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Regular)
       If myItalic And mybold Then
           TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)
       ElseIf myItalic Then
           TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)
       ElseIf mybold Then
           TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)
       End If
   End Sub

End Class <Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.CheckBox1 = New System.Windows.Forms.CheckBox
       Me.CheckBox2 = New System.Windows.Forms.CheckBox
       Me.GroupBox1 = New System.Windows.Forms.GroupBox
       Me.RadioButton1 = New System.Windows.Forms.RadioButton
       Me.RadioButton2 = New System.Windows.Forms.RadioButton
       Me.TextBox1 = New System.Windows.Forms.TextBox
       Me.GroupBox1.SuspendLayout()
       Me.SuspendLayout()
       "
       "CheckBox1
       "
       Me.CheckBox1.AutoSize = True
       Me.CheckBox1.Location = New System.Drawing.Point(230, 34)
       Me.CheckBox1.Name = "CheckBox1"
       Me.CheckBox1.Size = New System.Drawing.Size(48, 16)
       Me.CheckBox1.TabIndex = 1
       Me.CheckBox1.Text = "Italic"
       Me.CheckBox1.UseVisualStyleBackColor = True
       "
       "CheckBox2
       "
       Me.CheckBox2.AutoSize = True
       Me.CheckBox2.Location = New System.Drawing.Point(230, 56)
       Me.CheckBox2.Name = "CheckBox2"
       Me.CheckBox2.Size = New System.Drawing.Size(48, 16)
       Me.CheckBox2.TabIndex = 2
       Me.CheckBox2.Text = "Bold"
       Me.CheckBox2.UseVisualStyleBackColor = True
       "
       "GroupBox1
       "
       Me.GroupBox1.Controls.Add(Me.RadioButton2)
       Me.GroupBox1.Controls.Add(Me.RadioButton1)
       Me.GroupBox1.Location = New System.Drawing.Point(224, 85)
       Me.GroupBox1.Name = "GroupBox1"
       Me.GroupBox1.Size = New System.Drawing.Size(132, 77)
       Me.GroupBox1.TabIndex = 3
       Me.GroupBox1.TabStop = False
       Me.GroupBox1.Text = "Font size"
       "
       "RadioButton1
       "
       Me.RadioButton1.AutoSize = True
       Me.RadioButton1.Location = New System.Drawing.Point(6, 20)
       Me.RadioButton1.Name = "RadioButton1"
       Me.RadioButton1.Size = New System.Drawing.Size(59, 16)
       Me.RadioButton1.TabIndex = 1
       Me.RadioButton1.TabStop = True
       Me.RadioButton1.Text = "Larger font"
       Me.RadioButton1.UseVisualStyleBackColor = True
       "
       "RadioButton2
       "
       Me.RadioButton2.AutoSize = True
       Me.RadioButton2.Location = New System.Drawing.Point(6, 42)
       Me.RadioButton2.Name = "RadioButton2"
       Me.RadioButton2.Size = New System.Drawing.Size(59, 16)
       Me.RadioButton2.TabIndex = 2
       Me.RadioButton2.TabStop = True
       Me.RadioButton2.Text = "Smaller font"
       Me.RadioButton2.UseVisualStyleBackColor = True
       "
       "TextBox1
       "
       Me.TextBox1.Location = New System.Drawing.Point(12, 12)
       Me.TextBox1.Multiline = True
       Me.TextBox1.Name = "TextBox1"
       Me.TextBox1.Size = New System.Drawing.Size(195, 150)
       Me.TextBox1.TabIndex = 4
       Me.TextBox1.Text = "www.vbex.ru"
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(368, 174)
       Me.Controls.Add(Me.TextBox1)
       Me.Controls.Add(Me.GroupBox1)
       Me.Controls.Add(Me.CheckBox2)
       Me.Controls.Add(Me.CheckBox1)
       Me.Name = "Form1"
       Me.Text = "Form1"
       Me.GroupBox1.ResumeLayout(False)
       Me.GroupBox1.PerformLayout()
       Me.ResumeLayout(False)
       Me.PerformLayout()
   End Sub
   Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
   Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
   Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
   Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
   Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
   Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

End Class</source>