Option Strict Off
Option Explicit On 
Imports System.Text

Public Class StopWatch
    Inherits System.Windows.Forms.Form

#Region " Windows tH[ fUCiŐꂽR[h "

    Public Sub New()
        MyBase.New()

        ' ̌Ăяo Windows tH[ fUCiŕKvłB
        InitializeComponent()

        ' InitializeComponent() Ăяǒɏǉ܂B

    End Sub

    ' Form  dispose I[o[ChăR|[lgꗗ܂B
    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 tH[ fUCiŕKvłB
    Private components As System.ComponentModel.IContainer

    '  : ȉ̃vV[ẂAWindows tH[ fUCiŕKvłB
    ' Windows tH[ fUCigĕύXĂB  
    ' R[h GfB^͎gpȂłB
Friend WithEvents Button_TimInit As System.Windows.Forms.Button
Friend WithEvents Button_CountStart As System.Windows.Forms.Button
Friend WithEvents Button_CountLap As System.Windows.Forms.Button
Friend WithEvents Button_CountReset As System.Windows.Forms.Button
Friend WithEvents Button_CountStop As System.Windows.Forms.Button
Friend WithEvents Button_TimExit As System.Windows.Forms.Button
Friend WithEvents Button_Exit As System.Windows.Forms.Button
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label_Time As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Text_DeviceName As System.Windows.Forms.TextBox
Friend WithEvents Label_ProductName As System.Windows.Forms.Label
Friend WithEvents Text_ReturnCode As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button_TimInit = New System.Windows.Forms.Button
        Me.Button_CountStart = New System.Windows.Forms.Button
        Me.Button_CountLap = New System.Windows.Forms.Button
        Me.Button_CountReset = New System.Windows.Forms.Button
        Me.Button_CountStop = New System.Windows.Forms.Button
        Me.Button_TimExit = New System.Windows.Forms.Button
        Me.Button_Exit = New System.Windows.Forms.Button
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Label_ProductName = New System.Windows.Forms.Label
        Me.Text_DeviceName = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label_Time = New System.Windows.Forms.Label
        Me.GroupBox3 = New System.Windows.Forms.GroupBox
        Me.Text_ReturnCode = New System.Windows.Forms.TextBox
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.SuspendLayout()
        '
        'Button_TimInit
        '
        Me.Button_TimInit.Location = New System.Drawing.Point(232, 8)
        Me.Button_TimInit.Name = "Button_TimInit"
        Me.Button_TimInit.Size = New System.Drawing.Size(99, 20)
        Me.Button_TimInit.TabIndex = 0
        Me.Button_TimInit.Text = "TimInit"
        '
        'Button_CountStart
        '
        Me.Button_CountStart.Location = New System.Drawing.Point(232, 32)
        Me.Button_CountStart.Name = "Button_CountStart"
        Me.Button_CountStart.Size = New System.Drawing.Size(99, 20)
        Me.Button_CountStart.TabIndex = 1
        Me.Button_CountStart.Text = "CountStart"
        '
        'Button_CountLap
        '
        Me.Button_CountLap.Location = New System.Drawing.Point(232, 56)
        Me.Button_CountLap.Name = "Button_CountLap"
        Me.Button_CountLap.Size = New System.Drawing.Size(99, 20)
        Me.Button_CountLap.TabIndex = 2
        Me.Button_CountLap.Text = "CountLap"
        '
        'Button_CountReset
        '
        Me.Button_CountReset.Location = New System.Drawing.Point(232, 80)
        Me.Button_CountReset.Name = "Button_CountReset"
        Me.Button_CountReset.Size = New System.Drawing.Size(99, 20)
        Me.Button_CountReset.TabIndex = 3
        Me.Button_CountReset.Text = "CountReset"
        '
        'Button_CountStop
        '
        Me.Button_CountStop.Location = New System.Drawing.Point(232, 104)
        Me.Button_CountStop.Name = "Button_CountStop"
        Me.Button_CountStop.Size = New System.Drawing.Size(99, 20)
        Me.Button_CountStop.TabIndex = 4
        Me.Button_CountStop.Text = "CountStop"
        '
        'Button_TimExit
        '
        Me.Button_TimExit.Location = New System.Drawing.Point(232, 128)
        Me.Button_TimExit.Name = "Button_TimExit"
        Me.Button_TimExit.Size = New System.Drawing.Size(99, 20)
        Me.Button_TimExit.TabIndex = 5
        Me.Button_TimExit.Text = "TimExit"
        '
        'Button_Exit
        '
        Me.Button_Exit.Location = New System.Drawing.Point(232, 152)
        Me.Button_Exit.Name = "Button_Exit"
        Me.Button_Exit.Size = New System.Drawing.Size(99, 20)
        Me.Button_Exit.TabIndex = 6
        Me.Button_Exit.Text = "Exit"
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.Label_ProductName)
        Me.GroupBox1.Controls.Add(Me.Text_DeviceName)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(216, 72)
        Me.GroupBox1.TabIndex = 7
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = ""
        '
        'Label_ProductName
        '
        Me.Label_ProductName.Location = New System.Drawing.Point(80, 48)
        Me.Label_ProductName.Name = "Label_ProductName"
        Me.Label_ProductName.Size = New System.Drawing.Size(128, 16)
        Me.Label_ProductName.TabIndex = 3
        Me.Label_ProductName.Text = ""
        '
        'Text_DeviceName
        '
        Me.Text_DeviceName.Location = New System.Drawing.Point(80, 20)
        Me.Text_DeviceName.Name = "Text_DeviceName"
        Me.Text_DeviceName.Size = New System.Drawing.Size(104, 19)
        Me.Text_DeviceName.TabIndex = 2
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 48)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(56, 16)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "iF"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(64, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "foCXF"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.Label4)
        Me.GroupBox2.Controls.Add(Me.Label_Time)
        Me.GroupBox2.Location = New System.Drawing.Point(8, 88)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(216, 80)
        Me.GroupBox2.TabIndex = 8
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "oߎ"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(168, 40)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(32, 16)
        Me.Label4.TabIndex = 1
        Me.Label4.Text = "[us]"
        '
        'Label_Time
        '
        Me.Label_Time.Location = New System.Drawing.Point(8, 40)
        Me.Label_Time.Name = "Label_Time"
        Me.Label_Time.Size = New System.Drawing.Size(152, 16)
        Me.Label_Time.TabIndex = 0
        Me.Label_Time.Text = "0"
        Me.Label_Time.TextAlign = System.Drawing.ContentAlignment.TopRight
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.Add(Me.Text_ReturnCode)
        Me.GroupBox3.Location = New System.Drawing.Point(8, 176)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(328, 48)
        Me.GroupBox3.TabIndex = 9
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "߂l"
        '
        'Text_ReturnCode
        '
        Me.Text_ReturnCode.Location = New System.Drawing.Point(8, 16)
        Me.Text_ReturnCode.Name = "Text_ReturnCode"
        Me.Text_ReturnCode.Size = New System.Drawing.Size(312, 19)
        Me.Text_ReturnCode.TabIndex = 0
        '
        'StopWatch
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(344, 230)
        Me.Controls.Add(Me.GroupBox3)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.Button_Exit)
        Me.Controls.Add(Me.Button_TimExit)
        Me.Controls.Add(Me.Button_CountStop)
        Me.Controls.Add(Me.Button_CountReset)
        Me.Controls.Add(Me.Button_CountLap)
        Me.Controls.Add(Me.Button_CountStart)
        Me.Controls.Add(Me.Button_TimInit)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "StopWatch"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "XgbvEHb`"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox3.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim CountId As Short

    '==============================================================================
    ' TimInit
    '==============================================================================
    Private Sub Button_TimInit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_TimInit.Click
        Dim DeviceName As New String("", 256)
        Dim ProductName As New String("", 256)
        Dim ErrorString As New StringBuilder("", 256)
        Dim Ret As Integer

        '-----------------------------------
        ' foCX擾 (256ɌŒ)
        '-----------------------------------
        DeviceName = Text_DeviceName.Text.PadRight(256, ControlChars.NullChar)
        '-----------------------------------
        ' 
        '-----------------------------------
        Ret = TimInit(DeviceName, ProductName)
        '-----------------------------------
        ' G[
        '-----------------------------------
        Call TimGetErrorString(Ret, ErrorString)
        Text_ReturnCode.Text = "TimInit Ret = " & Ret & " " & ErrorString.ToString()
        If Ret = TIM_ERR_SUCCESS Then
            Text_DeviceName.Text = DeviceName
            Label_ProductName.Text = ProductName
        End If
    End Sub

    '==============================================================================
    ' JEgJn
    '==============================================================================
    Private Sub Button_CountStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_CountStart.Click
        Dim ErrorString As New StringBuilder("", 256)
        Dim Ret As Integer

        '-----------------------------------
        ' JEgJn
        '-----------------------------------
        Ret = TimCountStart(CountId)
        '-----------------------------------
        ' G[
        '-----------------------------------
        Call TimGetErrorString(Ret, ErrorString)
        Text_ReturnCode.Text = "TimCountStart Ret = " & Ret & " " & ErrorString.ToString()
    End Sub

    '==============================================================================
    ' bv^C擾
    '==============================================================================
    Private Sub Button_CountLap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_CountLap.Click
        Dim Microseconds As Integer
        Dim ErrorString As New StringBuilder("", 256)
        Dim Ret As Integer

        '-----------------------------------
        ' bv^C擾
        '-----------------------------------
        Ret = TimCountLap(CountId, Microseconds)
        '-----------------------------------
        ' G[
        '-----------------------------------
        Call TimGetErrorString(Ret, ErrorString)
        Text_ReturnCode.Text = "TimCountLap Ret = " & Ret & " " & ErrorString.ToString()
        If Ret = TIM_ERR_SUCCESS Then
            Label_Time.Text = Microseconds.ToString
        End If
    End Sub

    '==============================================================================
    ' JEgZbg
    '==============================================================================
    Private Sub Button_CountReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_CountReset.Click
        Dim ErrorString As New StringBuilder("", 256)
        Dim Ret As Integer

        '-----------------------------------
        ' JEgZbg
        '-----------------------------------
        Ret = TimCountReset(CountId)
        '-----------------------------------
        ' G[
        '-----------------------------------
        Call TimGetErrorString(Ret, ErrorString)
        Text_ReturnCode.Text = "TimCountReset Ret = " & Ret & " " & ErrorString.ToString()
    End Sub

    '==============================================================================
    ' JEg~
    '==============================================================================
    Private Sub Button_CountStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_CountStop.Click
        Dim Microseconds As Integer
        Dim ErrorString As New StringBuilder("", 256)
        Dim Ret As Integer

        '-----------------------------------
        ' JEg~
        '-----------------------------------
        Ret = TimCountStop(CountId, Microseconds)
        '-----------------------------------
        ' G[
        '-----------------------------------
        Call TimGetErrorString(Ret, ErrorString)
        Text_ReturnCode.Text = "TimCountStop Ret = " & Ret & " " & ErrorString.ToString()
        If Ret = TIM_ERR_SUCCESS Then
            Label_Time.Text = Microseconds.ToString
        End If
    End Sub

    '==============================================================================
    ' TimExit
    '==============================================================================
    Private Sub Button_TimExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_TimExit.Click
        Dim ErrorString As New StringBuilder("", 256)
        Dim Ret As Integer

        '-----------------------------------
        ' I
        '-----------------------------------
        Ret = TimExit()
        '-----------------------------------
        ' G[
        '-----------------------------------
        Call TimGetErrorString(Ret, ErrorString)
        Text_ReturnCode.Text = "TimExit Ret = " & Ret & " " & ErrorString.ToString()
    End Sub

    '==============================================================================
    ' I
    '==============================================================================
    Private Sub Button_Exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Exit.Click
        '-----------------------------------
        ' I
        '-----------------------------------
        Call TimExit()
        '-----------------------------------
        ' _CAOI
        '-----------------------------------
        End
    End Sub

End Class
