Public Class frm0311VBVC
    Inherits System.Windows.Forms.Form
    Private WithEvents mobjCalc As VC04.cls0311VC04

#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 txtNum1 As System.Windows.Forms.TextBox
    Friend WithEvents cboTerm As System.Windows.Forms.ComboBox
    Friend WithEvents txtNum2 As System.Windows.Forms.TextBox
    Friend WithEvents cmdCalc As System.Windows.Forms.Button
    Friend WithEvents txtAns As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.txtNum1 = New System.Windows.Forms.TextBox
        Me.cboTerm = New System.Windows.Forms.ComboBox
        Me.txtNum2 = New System.Windows.Forms.TextBox
        Me.cmdCalc = New System.Windows.Forms.Button
        Me.txtAns = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'txtNum1
        '
        Me.txtNum1.ImeMode = System.Windows.Forms.ImeMode.Disable
        Me.txtNum1.Location = New System.Drawing.Point(64, 8)
        Me.txtNum1.MaxLength = 10
        Me.txtNum1.Name = "txtNum1"
        Me.txtNum1.Size = New System.Drawing.Size(216, 19)
        Me.txtNum1.TabIndex = 0
        Me.txtNum1.Text = "txtNum1"
        Me.txtNum1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'cboTerm
        '
        Me.cboTerm.Location = New System.Drawing.Point(8, 32)
        Me.cboTerm.Name = "cboTerm"
        Me.cboTerm.Size = New System.Drawing.Size(48, 20)
        Me.cboTerm.TabIndex = 1
        '
        'txtNum2
        '
        Me.txtNum2.ImeMode = System.Windows.Forms.ImeMode.Disable
        Me.txtNum2.Location = New System.Drawing.Point(64, 32)
        Me.txtNum2.MaxLength = 10
        Me.txtNum2.Name = "txtNum2"
        Me.txtNum2.Size = New System.Drawing.Size(216, 19)
        Me.txtNum2.TabIndex = 2
        Me.txtNum2.Text = "txtNum2"
        Me.txtNum2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'cmdCalc
        '
        Me.cmdCalc.Location = New System.Drawing.Point(8, 56)
        Me.cmdCalc.Name = "cmdCalc"
        Me.cmdCalc.Size = New System.Drawing.Size(272, 24)
        Me.cmdCalc.TabIndex = 3
        Me.cmdCalc.Text = "計算(&C)"
        '
        'txtAns
        '
        Me.txtAns.ImeMode = System.Windows.Forms.ImeMode.Disable
        Me.txtAns.Location = New System.Drawing.Point(64, 88)
        Me.txtAns.Name = "txtAns"
        Me.txtAns.ReadOnly = True
        Me.txtAns.Size = New System.Drawing.Size(216, 19)
        Me.txtAns.TabIndex = 4
        Me.txtAns.TabStop = False
        Me.txtAns.Text = "txtAns"
        Me.txtAns.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'frm0311VBVC
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(288, 118)
        Me.Controls.Add(Me.txtAns)
        Me.Controls.Add(Me.cmdCalc)
        Me.Controls.Add(Me.txtNum2)
        Me.Controls.Add(Me.cboTerm)
        Me.Controls.Add(Me.txtNum1)
        Me.Name = "frm0311VBVC"
        Me.Text = "VB → C++ Sample"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub frm0311VB01_Load(ByVal sender As System.Object, _
                                 ByVal e As System.EventArgs) _
                                 Handles MyBase.Load
        '演算子の設定
        Me.cboTerm.DropDownStyle = ComboBoxStyle.DropDownList
        Me.cboTerm.BeginUpdate()
        Me.cboTerm.Items.Clear()
        Me.cboTerm.Items.Add("＋")
        Me.cboTerm.Items.Add("−")
        Me.cboTerm.Items.Add("×")
        Me.cboTerm.Items.Add("÷")
        Me.cboTerm.EndUpdate()
        'フィールドの初期化
        Me.txtNum1.Text = ""
        Me.txtNum2.Text = ""
        Me.txtAns.Text = ""
    End Sub

    Private Sub subNumCheck(ByVal sender As Object, _
                            ByVal e As System.Windows.Forms.KeyPressEventArgs) _
                            Handles txtNum1.KeyPress, _
                                    txtNum2.KeyPress
        If e.KeyChar = "." Then
            '小数点は１つだけ許可する
            If sender.text.IndexOf(".") > 0 Then
                e.Handled = True
            End If
        ElseIf (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso _
                e.KeyChar <> ControlChars.Back Then
            '数字とBS以外はキャンセル(delや→でKeypressは発生しない)
            e.Handled = True
        End If
    End Sub

    Private Sub subGotFocus(ByVal sender As Object, _
                            ByVal e As System.EventArgs) _
                            Handles txtNum1.GotFocus, _
                                    txtNum2.GotFocus, _
                                    cboTerm.GotFocus
        'ハイライト表示
        sender.BackColor = System.Drawing.Color.Lime
    End Sub

    Private Sub subLostFocus(ByVal sender As Object, _
                             ByVal e As System.EventArgs) _
                             Handles txtNum1.LostFocus, _
                                     txtNum2.LostFocus, _
                                     cboTerm.LostFocus
        'ハイライト非表示
        sender.BackColor = System.Drawing.SystemColors.Info
    End Sub

    Private Sub cmdCalc_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) _
                              Handles cmdCalc.Click

        mobjCalc = New VC04.cls0311VC04
        Me.txtAns.Text = mobjCalc.pdblCalc(Me.txtNum1.Text, _
                                           Me.txtNum2.Text, _
                                           Me.cboTerm.Text)
        mobjCalc = Nothing
    End Sub

    Private Sub mobjCalc_pevtError(ByVal vintError As Integer, _
                                   ByVal vstrError As String) _
                                   Handles mobjCalc.pevtError
        MessageBox.Show(vstrError, _
                        Me.Text, _
                        MessageBoxButtons.OK, _
                        MessageBoxIcon.Warning)
    End Sub
End Class
