基本的に誰かが押すbutton2
と、プログラムに測定をリセットさせたいと思います。実際のコードは永遠に測定を続けており、その測定をリセットしたいだけです。英語が下手で申し訳ありません。私が本当に欲しいものを理解していただければ幸いです。そうでない場合は、詳しく説明します。
これが私のコードです:
Public Class Form1
Private MonitorWidth As Double = 51.5 'cm
Private MonitorHeigth As Double = 31 'cm - This must be enter by the user
Private TotalDistance As Double
Private PixelHeigth As Double 'cm
Private PixelWidth As Double 'cm
Private WithEvents TTimer As New Timers.Timer
Private PointQueue As New Queue(Of Point)(100)
Private Lastpoint As Point
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
TTimer.Stop()
While PointQueue.Count > 0
Dim P As Point = PointQueue.Dequeue
TotalDistance += Math.Sqrt(((Lastpoint.X - P.X) * PixelWidth) ^ 2 + ((Lastpoint.Y - P.Y) * PixelHeigth) ^ 2)
Lastpoint = P
TextBox1.Text = Format(TotalDistance, "Distance: #,##0.0 cm")
TTimer.Start()
End While
End Sub
Private Sub TTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles TTimer.Elapsed
PointQueue.Enqueue(MousePosition)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Enabled = True Then
Lastpoint = MousePosition
TTimer.AutoReset = True
TTimer.Interval = 5
TTimer.Start()
Dim ScreenBounds As Rectangle = Screen.GetBounds(New Point(0, 0))
Dim Screenwidth_Pixel As Integer = ScreenBounds.Width
Dim screenHeigth_Pixel As Integer = ScreenBounds.Height
PixelHeigth = MonitorHeigth / screenHeigth_Pixel
PixelWidth = MonitorWidth / Screenwidth_Pixel
Timer1.Interval = 200
Timer1.Start()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button2.Enabled = True Then
Timer1.Stop()
TextBox1.Text = ""
TextBox1.Text = Format(TotalDistance = 0)
End If
End Sub
End Class