VB.Net/GUI — различия между версиями

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

Текущая версия на 12:44, 26 мая 2010

Display All font installed in your system

Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Public Class MainClass
  Shared Sub Main()
     Dim form1 As Form1 = new Form1
     Application.Run(form1)
  End Sub
  
End Class


Public Class Form1
  Inherits System.Windows.Forms.Form
#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 panel As System.Windows.Forms.Panel
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.panel = New System.Windows.Forms.Panel()
    Me.SuspendLayout()
    "
    "panel
    "
    Me.panel.AutoScroll = True
    Me.panel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    Me.panel.Location = New System.Drawing.Point(19, 21)
    Me.panel.Name = "panel"
    Me.panel.Size = New System.Drawing.Size(304, 280)
    Me.panel.TabIndex = 3
    "
    "Form1
    "
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(342, 323)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.panel})
    Me.MaximizeBox = False
    Me.MinimizeBox = False
    Me.Name = "Form1"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.Text = "Form1"
    Me.ResumeLayout(False)
  End Sub
#End Region
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim Style As FontStyle
    Dim y As Int32 = 0
    Dim ff As FontFamily
    For Each ff In FontFamily.Families
      Style = FontStyle.Regular
      If ff.IsStyleAvailable(Style) Then
        AddString(ff, y, Style)
      End If
    Next
  End Sub
  Private Sub AddString(ByVal ff As FontFamily, ByRef y As Int32, ByVal Style As FontStyle)
    Dim fnt As Font = New Font(ff, 12, Style, GraphicsUnit.Pixel)
    Dim LineSpace As Int32 = CInt((ff.GetLineSpacing(Style)) * _
                              fnt.Size / ff.GetEmHeight(Style))
    y += LineSpace + 2
    Dim pictureBox As PictureBox = New PictureBox()
    pictureBox.Height = LineSpace
    pictureBox.Width = panel.Width
    Dim B As Bitmap = New Bitmap(pictureBox.Width, pictureBox.Height)
    Dim G As Graphics = Graphics.FromImage(B)
    G.DrawString(ff.Name + " : Style = " + Style.ToString(), _
                    fnt, Brushes.Black, 0, 0)
    pictureBox.Image = B
    panel.Controls.Add(pictureBox)
    panel.Controls(panel.Controls.Count - 1).Location = New Point(2, y)
    If y < panel.Height Then
      panel.Refresh()
    End If
    fnt.Dispose()
    G.Dispose()
  End Sub
End Class


Font dialog in VB.net

Imports System
Imports System.Collections
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Resources
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class MainClass
    Shared Sub Main()
        Dim dlg As FontDialog = New FontDialog()
        Dim res As DialogResult = dlg.ShowDialog()
    End Sub
End Class


Font dialog: turn color option on

Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing
Public Class MainClass
    
    Shared Sub Main()
        Dim dlgFont As System.Windows.Forms.FontDialog
        dlgFont = New System.Windows.Forms.FontDialog
        
        dlgFont.ShowColor = True
        If dlgFont.ShowDialog() = DialogResult.OK Then
        End If
    End Sub
End Class


Font Properties in Bigger Font size

Imports System
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Globalization
Imports System.Text
Imports System.Collections
Public Class MainClass
    Shared Sub Main()
        Dim myform As Form = New FontSizesForm()
        Application.Run(myform)
    End Sub
End Class
Public Class FontSizesForm
    Inherits System.Windows.Forms.Form
#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 listBox1 As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.listBox1 = New System.Windows.Forms.ListBox()
        Me.SuspendLayout()
        "
        "listBox1
        "
        Me.listBox1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.listBox1.Font = New System.Drawing.Font("Courier New", 14.0!)
        Me.listBox1.IntegralHeight = False
        Me.listBox1.ItemHeight = 21
        Me.listBox1.Name = "listBox1"
        Me.listBox1.Size = New System.Drawing.Size(560, 182)
        Me.listBox1.TabIndex = 1
        "
        "FontSizesForm
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(560, 182)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.listBox1})
        Me.Name = "FontSizesForm"
        Me.Text = "FontSizesForm"
        Me.ResumeLayout(False)
    End Sub
#End Region
    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()
        listBox1.Items.Add(String.Format("Font.Name=                       {0}", Me.Font.Name))
        listBox1.Items.Add(String.Format("Font.FontFamly.Name=             {0}", Me.Font.FontFamily.Name))
        listBox1.Items.Add(String.Format("Font.Size=                       {0} {1}s (specified Unit)", Me.Font.Size, Me.Font.Unit.ToString()))
        listBox1.Items.Add(String.Format("Font.Height=                     {0} Pixels", Me.Font.Height))
        listBox1.Items.Add(String.Format("Font.GetHeight=                  {0} Pixels", Me.Font.GetHeight(g)))
        listBox1.Items.Add(String.Format("Font.SizeInPoints=               {0} Points", Me.Font.SizeInPoints.ToString()))
        listBox1.Items.Add(String.Format("GetPixels(Font.SizeInPoints)=    {0} Pixels", GetPixelsFromPoints(Me.Font.SizeInPoints, g.DpiY)))
        "listBox1.Items.Add(string.Format("GetInches(Font.SizeInPoints)=    {0} Inches", GetInchesFromPoints(Me.Font.SizeInPoints, g.DpiY)))
        listBox1.Items.Add(String.Format("Font.FontFamily.GetEmHeight=     {0} Design Units", Me.Font.FontFamily.GetEmHeight(FontStyle.Regular)))
        listBox1.Items.Add(String.Format("GetPixels(GetEmHeight)=          {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetEmHeight(Me.Font.Style), Me.Font, g.DpiY)))
        listBox1.Items.Add(String.Format("Font.FontFamily.GetLineSpacing=  {0} Design Units", Me.Font.FontFamily.GetLineSpacing(FontStyle.Regular)))
        listBox1.Items.Add(String.Format("GetPixels(GetLineSpacing)=       {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetLineSpacing(Me.Font.Style), Me.Font, g.DpiY)))
        listBox1.Items.Add(String.Format("Font.FontFamily.GetCellAscent=   {0} Design Units", Me.Font.FontFamily.GetCellAscent(FontStyle.Regular)))
        listBox1.Items.Add(String.Format("GetPixels(GetCellAscent)=        {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetCellAscent(Me.Font.Style), Me.Font, g.DpiY)))
        listBox1.Items.Add(String.Format("Font.FontFamily.GetCellDescent=  {0} Design Units", Me.Font.FontFamily.GetCellDescent(FontStyle.Regular)))
        listBox1.Items.Add(String.Format("GetPixels(GetCellDescent)=       {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetCellDescent(Me.Font.Style), Me.Font, g.DpiY)))
        listBox1.Items.Add(String.Format("Padding=                         {0} Design Units", Me.Font.FontFamily.GetLineSpacing(FontStyle.Regular) - (Me.Font.FontFamily.GetCellAscent(FontStyle.Regular) + Me.Font.FontFamily.GetCellDescent(FontStyle.Regular))))
        listBox1.Items.Add(String.Format("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


Get Installed Font and display one by one

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.IO

public class MainClass
   Shared Sub Main()
      Dim form1 As Form = New FontViewer
      Application.Run(form1)
   End Sub
End Class


Public Class FontViewer
    Inherits System.Windows.Forms.Form
#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 StatusBar As System.Windows.Forms.StatusBar
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents lstFonts As System.Windows.Forms.ruboBox
    Friend WithEvents label1 As System.Windows.Forms.Label
    Friend WithEvents Panel As System.Windows.Forms.StatusBarPanel
    Friend WithEvents lstSize As System.Windows.Forms.ruboBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.StatusBar = New System.Windows.Forms.StatusBar()
        Me.Panel = New System.Windows.Forms.StatusBarPanel()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.lstSize = New System.Windows.Forms.ruboBox()
        Me.lstFonts = New System.Windows.Forms.ruboBox()
        Me.label1 = New System.Windows.Forms.Label()
        CType(Me.Panel, System.ruponentModel.ISupportInitialize).BeginInit()
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        "
        "StatusBar
        "
        Me.StatusBar.Location = New System.Drawing.Point(0, 150)
        Me.StatusBar.Name = "StatusBar"
        Me.StatusBar.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.Panel})
        Me.StatusBar.ShowPanels = True
        Me.StatusBar.Size = New System.Drawing.Size(552, 20)
        Me.StatusBar.TabIndex = 3
        "
        "Panel
        "
        Me.Panel.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring
        Me.Panel.Width = 536
        "
        "GroupBox1
        "
        Me.GroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.lstSize, Me.lstFonts, Me.label1})
        Me.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.GroupBox1.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.GroupBox1.Location = New System.Drawing.Point(4, 4)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(544, 40)
        Me.GroupBox1.TabIndex = 2
        Me.GroupBox1.TabStop = False
        "
        "lstSize
        "
        Me.lstSize.DropDownWidth = 40
        Me.lstSize.Location = New System.Drawing.Point(448, 12)
        Me.lstSize.MaxDropDownItems = 20
        Me.lstSize.Name = "lstSize"
        Me.lstSize.Size = New System.Drawing.Size(68, 21)
        Me.lstSize.TabIndex = 2
        "
        "lstFonts
        "
        Me.lstFonts.DropDownStyle = System.Windows.Forms.ruboBoxStyle.DropDownList
        Me.lstFonts.DropDownWidth = 340
        Me.lstFonts.Location = New System.Drawing.Point(100, 12)
        Me.lstFonts.MaxDropDownItems = 20
        Me.lstFonts.Name = "lstFonts"
        Me.lstFonts.Size = New System.Drawing.Size(340, 21)
        Me.lstFonts.TabIndex = 1
        "
        "label1
        "
        Me.label1.Location = New System.Drawing.Point(12, 16)
        Me.label1.Name = "label1"
        Me.label1.Size = New System.Drawing.Size(80, 12)
        Me.label1.TabIndex = 0
        Me.label1.Text = "Choose Font:"
        "
        "FontViewer
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(552, 170)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.StatusBar, Me.GroupBox1})
        Me.Name = "FontViewer"
        Me.Text = "Font Viewer"
        CType(Me.Panel, System.ruponentModel.ISupportInitialize).EndInit()
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)
    End Sub
#End Region

    Private Sub lstFonts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstFonts.SelectedIndexChanged
        " Trigger a refresh and repaint.
        If lstFonts.SelectedIndex <> -1 Then Me.Invalidate()
    End Sub

    Private Sub FontViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Fonts As New System.Drawing.Text.InstalledFontCollection()
        Dim Family As FontFamily
        For Each Family In Fonts.Families
            lstFonts.Items.Add(Family.Name)
        Next
        Dim i As Integer
        For i = 10 To 100
            lstSize.Items.Add(i)
        Next
        lstSize.Text = "50"
    End Sub
    Private Sub FontViewer_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        If lstFonts.SelectedIndex <> -1 Then
            Try
                e.Graphics.DrawString(lstFonts.Text, New Font(lstFonts.Text, Val(lstSize.Text)), Brushes.Black, 10, 50)
                StatusBar.Panels(0).Text = ""
            Catch err As Exception
                StatusBar.Panels(0).Text = err.Message
            End Try
        End If
    End Sub
    Private Sub lstSize_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstSize.SelectedIndexChanged
        If Val(lstSize.Text) = 0 Then
            lstSize.Text = "50"
        End If
        Me.Invalidate()
    End Sub
End Class


Installed Font Collection in Your System

Imports System
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Globalization
Imports System.Text
Imports System.Collections
Public Class MainClass
    Shared Sub Main()
        Dim myform As Form = New FontFamiliesForm()
        Application.Run(myform)
    End Sub
End Class

Public Class FontFamiliesForm
    Inherits System.Windows.Forms.Form
#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 groupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents installedFamiliesListBox As System.Windows.Forms.ListBox
    Friend WithEvents groupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents familiesListBox As System.Windows.Forms.ListBox
    Friend WithEvents splitter1 As System.Windows.Forms.Splitter
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.groupBox2 = New System.Windows.Forms.GroupBox()
        Me.installedFamiliesListBox = New System.Windows.Forms.ListBox()
        Me.groupBox1 = New System.Windows.Forms.GroupBox()
        Me.familiesListBox = New System.Windows.Forms.ListBox()
        Me.splitter1 = New System.Windows.Forms.Splitter()
        Me.groupBox2.SuspendLayout()
        Me.groupBox1.SuspendLayout()
        Me.SuspendLayout()
        "
        "groupBox2
        "
        Me.groupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.installedFamiliesListBox})
        Me.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.groupBox2.Location = New System.Drawing.Point(139, 0)
        Me.groupBox2.Name = "groupBox2"
        Me.groupBox2.Size = New System.Drawing.Size(153, 310)
        Me.groupBox2.TabIndex = 5
        Me.groupBox2.TabStop = False
        Me.groupBox2.Text = "Installed Font Families"
        "
        "installedFamiliesListBox
        "
        Me.installedFamiliesListBox.Dock = System.Windows.Forms.DockStyle.Fill
        Me.installedFamiliesListBox.IntegralHeight = False
        Me.installedFamiliesListBox.Location = New System.Drawing.Point(3, 16)
        Me.installedFamiliesListBox.Name = "installedFamiliesListBox"
        Me.installedFamiliesListBox.Size = New System.Drawing.Size(147, 291)
        Me.installedFamiliesListBox.TabIndex = 0
        "
        "groupBox1
        "
        Me.groupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.familiesListBox})
        Me.groupBox1.Dock = System.Windows.Forms.DockStyle.Left
        Me.groupBox1.Location = New System.Drawing.Point(3, 0)
        Me.groupBox1.Name = "groupBox1"
        Me.groupBox1.Size = New System.Drawing.Size(136, 310)
        Me.groupBox1.TabIndex = 3
        Me.groupBox1.TabStop = False
        Me.groupBox1.Text = "Font Families"
        "
        "familiesListBox
        "
        Me.familiesListBox.Dock = System.Windows.Forms.DockStyle.Fill
        Me.familiesListBox.IntegralHeight = False
        Me.familiesListBox.Location = New System.Drawing.Point(3, 16)
        Me.familiesListBox.Name = "familiesListBox"
        Me.familiesListBox.Size = New System.Drawing.Size(130, 291)
        Me.familiesListBox.TabIndex = 0
        "
        "splitter1
        "
        Me.splitter1.Name = "splitter1"
        Me.splitter1.Size = New System.Drawing.Size(3, 310)
        Me.splitter1.TabIndex = 4
        Me.splitter1.TabStop = False
        "
        "FontFamiliesForm
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 310)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.groupBox2, Me.groupBox1, Me.splitter1})
        Me.Name = "FontFamiliesForm"
        Me.Text = "FontFamiliesForm"
        Me.groupBox2.ResumeLayout(False)
        Me.groupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub FontFamiliesForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim family As FontFamily
        For Each family In FontFamily.Families
            If family.IsStyleAvailable(FontStyle.Bold) = False Then Exit For
            familiesListBox.Items.Add(family.Name)
        Next family
        Dim installedFonts As InstalledFontCollection = New InstalledFontCollection()
        For Each family In installedFonts.Families
            installedFamiliesListBox.Items.Add(family.Name)
        Next family
    End Sub
End Class


List Installed Fonts

Imports System
Imports System.Windows.Forms
Imports System.Drawing.Text
Imports System.Drawing
Public Class MainClass
    
    Shared Sub Main(ByVal args As String())
        " Get the installed fonts collection.
        Dim installed_fonts As New InstalledFontCollection
        " Get an array of the system"s font familiies.
        Dim font_families() As FontFamily = installed_fonts.Families()
        " Display the font families.
        For Each font_family As FontFamily In font_families
            Console.Write (font_family.Name & ", ")
        Next font_family
    End Sub
End Class


Show Font dialog and get select font and font color

Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing
Public Class MainClass
    
    Shared Sub Main()
        Dim dlgFont As System.Windows.Forms.FontDialog
        dlgFont = New System.Windows.Forms.FontDialog
        
        "dlgFont.Font = set your font here
        
        If dlgFont.ShowDialog() = DialogResult.OK Then
            Console.WriteLine( dlgFont.Font )
            Console.WriteLine( dlgFont.Color )
        End If
    End Sub
End Class


Use Font dialog to change TextBox font

Imports System
Imports System.Collections
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Printing

Public Class MainClass
    Shared Sub Main()
       Dim form1 As Form = New Form1()
       Application.Run(form1) 
    End Sub
End Class

Public Class Form1
    Inherits System.Windows.Forms.Form
#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
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    "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()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        "
        "TextBox1
        "
        Me.TextBox1.Location = New System.Drawing.Point(14, 24)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(264, 22)
        Me.TextBox1.TabIndex = 0
        Me.TextBox1.Text = "Change font!"
        "
        "Button1
        "
        Me.Button1.Location = New System.Drawing.Point(94, 208)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(120, 23)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Change font!"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
        Me.ClientSize = New System.Drawing.Size(320, 268)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.TextBox1})
        Me.Name = "Form1"
        Me.Text = "Changing the font of a text box"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myDialog As New FontDialog()
        If myDialog.ShowDialog() = DialogResult.OK Then
            TextBox1.Font = myDialog.Font
        End If
    End Sub
End Class