Public Class TextForm
    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 TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents FontList As System.Windows.Forms.ComboBox
    Friend WithEvents FontSize As System.Windows.Forms.ComboBox
    Friend WithEvents OKBtn As System.Windows.Forms.Button
    Friend WithEvents CancelBtn As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.FontSize = New System.Windows.Forms.ComboBox
        Me.FontList = New System.Windows.Forms.ComboBox
        Me.OKBtn = New System.Windows.Forms.Button
        Me.CancelBtn = New System.Windows.Forms.Button
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(8, 56)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(528, 168)
        Me.TextBox1.TabIndex = 0
        Me.TextBox1.Text = "TextBox1"
        '
        'Panel1
        '
        Me.Panel1.Controls.Add(Me.FontSize)
        Me.Panel1.Controls.Add(Me.FontList)
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Top
        Me.Panel1.Location = New System.Drawing.Point(0, 0)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(544, 40)
        Me.Panel1.TabIndex = 1
        '
        'FontSize
        '
        Me.FontSize.Items.AddRange(New Object() {"8", "9", "10", "10.5", "11", "12", "14", "16", "20", "22", "26", "31", "34", "38", "42", "50", "64"})
        Me.FontSize.Location = New System.Drawing.Point(272, 8)
        Me.FontSize.Name = "FontSize"
        Me.FontSize.Size = New System.Drawing.Size(56, 20)
        Me.FontSize.TabIndex = 1
        Me.FontSize.Text = "12"
        '
        'FontList
        '
        Me.FontList.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.FontList.Location = New System.Drawing.Point(16, 8)
        Me.FontList.Name = "FontList"
        Me.FontList.Size = New System.Drawing.Size(232, 20)
        Me.FontList.TabIndex = 0
        '
        'OKBtn
        '
        Me.OKBtn.Location = New System.Drawing.Point(360, 232)
        Me.OKBtn.Name = "OKBtn"
        Me.OKBtn.Size = New System.Drawing.Size(72, 32)
        Me.OKBtn.TabIndex = 2
        Me.OKBtn.Text = "&OK"
        '
        'CancelBtn
        '
        Me.CancelBtn.Location = New System.Drawing.Point(448, 232)
        Me.CancelBtn.Name = "CancelBtn"
        Me.CancelBtn.Size = New System.Drawing.Size(72, 32)
        Me.CancelBtn.TabIndex = 3
        Me.CancelBtn.Text = "キャンセル"
        '
        'TextForm
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(544, 278)
        Me.Controls.Add(Me.CancelBtn)
        Me.Controls.Add(Me.OKBtn)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.TextBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Name = "TextForm"
        Me.Text = "テキストの編集"
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim _fontname As String
    Dim _fontpt As Single
    Dim _fonttext As String

    Public Sub InitFontList()
        ' フォントリストを生成する
        FontList.Items.Clear()
        Dim g As Graphics = Me.CreateGraphics()
        For Each family As FontFamily In FontFamily.GetFamilies(g)
            FontList.Items.Add(family.Name())
        Next
        g.Dispose()
        FontList.Text = FontFamily.GenericMonospace.Name
    End Sub

    Public Property FontName() As String
        Get
            Return _fontname
        End Get
        Set(ByVal Value As String)
            _fontname = Value
            FontList.Text = _fontname
        End Set
    End Property

    Public Property FontPt() As Single
        Get
            Return _fontpt
        End Get
        Set(ByVal Value As Single)
            _fontpt = Value
            FontSize.Text = Value.ToString()
        End Set
    End Property

    Public Property FontText() As String
        Get
            Return _fonttext
        End Get
        Set(ByVal Value As String)
            _fonttext = Value
            TextBox1.Text = Value
        End Set
    End Property

    Private Sub CancelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CancelBtn.Click
        ' キャンセルボタン
        Me.DialogResult = DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OKBtn.Click
        ' OKボタン
        If Not IsNumeric(FontSize.Text) Then
            MsgBox("フォントサイズが数値ではありません", MsgBoxStyle.Exclamation)
            Exit Sub
        End If
        _fontname = FontList.Text
        _fontpt = CSng(FontSize.Text)
        _fonttext = TextBox1.Text
        Me.DialogResult = DialogResult.OK
        Me.Close()
    End Sub

    Private Sub TextForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitFontList()
    End Sub

End Class
