基本上如果有人按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
答案 0 :(得分:1)
在Button2
事件处理程序(Button2_Click
)中,重置队列:
PointQueue = New Queue(Of Point)(100)