Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 在Visual Basic中重置循环_Vb.net_Visual Studio 2010 - Fatal编程技术网

Vb.net 在Visual Basic中重置循环

Vb.net 在Visual Basic中重置循环,vb.net,visual-studio-2010,Vb.net,Visual Studio 2010,基本上,如果有人按下按钮2,我希望程序重置测量。实际上代码一直在测量,我只想重置测量值。对不起,我的英语不好,我希望你理解我真正想要的,如果不是,我会详细解释 这是我的密码: Public Class Form1 Private MonitorWidth As Double = 51.5 'cm Private MonitorHeigth As Double = 31 'cm - This must be enter by the user Private Total

基本上,如果有人按下
按钮2
,我希望程序重置测量。实际上代码一直在测量,我只想重置测量值。对不起,我的英语不好,我希望你理解我真正想要的,如果不是,我会详细解释

这是我的密码:

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

在您的
按钮2
事件处理程序(
按钮2\u单击
)中,重置队列:

PointQueue = New Queue(Of Point)(100)

试着使用一个全局变量,当你点击按钮时会重置。我刚把这个代码粘贴到按钮2中,它不起作用,测量继续,它不从开始0@SuoraAnne-我假设您的
点队列
是进行测量的地方。上述代码重置为空队列。你把它贴在哪里了?您是否调试并检查该行是否执行?@SuoraAnne-是的,您已经显示了该事件处理程序。但是您是否将其粘贴到了
If
中?你没有回答我关于通过调试的问题。是的,我已经将代码粘贴到了If中。我也检查了一下,这行代码似乎执行了。@SuoraAnne-太好了。我的假设是,
PrintQueue
是你测量的地方,这是正确的还是错误的?您需要将哪个变量设置为0?