Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows フォーム デザイナで生成されたコード "

    Public Sub New()
        MyBase.New()

        ' この呼び出しは Windows フォーム デザイナで必要です。
        InitializeComponent()

        ' InitializeComponent() 呼び出しの後に初期化を追加します。

    End Sub

    ' Form は、コンポーネント一覧に後処理を実行するために dispose をオーバーライドします。
    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

    ' Windows フォーム デザイナで必要です。
    Private components As System.ComponentModel.IContainer

    ' メモ : 以下のプロシージャは、Windows フォーム デザイナで必要です。
    'Windows フォーム デザイナを使って変更してください。  
    ' コード エディタを使って変更しないでください。
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.SuspendLayout()
        '
        'ListBox1
        '
        Me.ListBox1.ItemHeight = 12
        Me.ListBox1.Location = New System.Drawing.Point(24, 16)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(216, 52)
        Me.ListBox1.TabIndex = 0
        '
        'PictureBox1
        '
        Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.PictureBox1.Location = New System.Drawing.Point(16, 88)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(264, 150)
        Me.PictureBox1.TabIndex = 1
        Me.PictureBox1.TabStop = False
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(336, 277)
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.ListBox1)
        Me.Name = "Form1"
        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 Fonts As New System.Drawing.Text.InstalledFontCollection
        Dim fontFamilies() As FontFamily

        fontFamilies = Fonts.Families

        Dim cnt As Integer = fontFamilies.Length
        Dim i As Integer

        For i = 0 To cnt - 1
            Me.ListBox1.Items.Add(fontFamilies(i).Name)
        Next
        Me.ListBox1.SetSelected(0, True)

    End Sub

    Dim FontName As String

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        FontName = Me.ListBox1.SelectedItem
        Me.PictureBox1.Refresh()
    End Sub

    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        Dim NewBrush As New SolidBrush(Color.Black)
        Dim NewPoint As New RectangleF(10, 10, 250, 150)
        Dim NewFontFamily As New FontFamily(FontName)
        Dim NewFont As System.Drawing.Font

        If NewFontFamily.IsStyleAvailable(FontStyle.Regular) Then
            NewFont = New System.Drawing.Font(FontName, 20, FontStyle.Regular)
        ElseIf NewFontFamily.IsStyleAvailable(FontStyle.Bold) Then
            NewFont = New System.Drawing.Font(FontName, 20, FontStyle.Bold)
        ElseIf NewFontFamily.IsStyleAvailable(FontStyle.Italic) Then
            NewFont = New System.Drawing.Font(FontName, 20, FontStyle.Italic)
        End If
        e.Graphics.DrawString(FontName, NewFont, NewBrush, NewPoint)
    End Sub
End Class
