2016-05-09 73 views
0
Private Sub chkLoop_CheckedChanged(sender As Object, e As EventArgs) Handles chkLoop.CheckedChanged 
    intValue1 = nudX4.Value 
    intValue2 = nudY4.Value 
    Dim g As TrigLib.TrigLib = New TrigLib.TrigLib 
    ' Make the shape closed by making the last point the same as the first point. 
    If chkLoop.Checked Then 
     nudX4.Value = nudX1.Value 
     nudY4.Value = nudY1.Value 

     lblArea.Text = "Area: " & CInt(g.AreaTriangle(New Point(nudX1.Value, nudY1.Value), New Point(nudX2.Value, nudY2.Value), New Point(nudX3.Value, nudY3.Value))) 
    ElseIf chkLoop.CheckState = CheckState.Unchecked Then 
     nudX4.Value = intValue1 
     nudY4.Value = intValue2 
     lblArea.Text = "" 

我試圖將我先前的點nudX4和nudY4的值存儲在兩個局部變量中。但是當我取消選中我的複選框時,nudX4和nudY4的值仍然等於nudX1和nudY1的值,而不是變回以前的值。如何在更改vb.net之前跟蹤以前的值

請幫忙。

+1

想想那裏發生了什麼。每當'Checked'屬性值發生變化時,您都會將'nudX4'和'nudY4'的Value屬性複製到這些變量中。這意味着,如果您輸入ElseIf塊,則只需再次將這些相同的值複製回來即可。如果你只想在框選中時設置變量,那麼你需要把代碼設置在某個地方,只有當框被選中時纔會執行它。如果您已經調試過代碼,那麼問題就會很明顯,所以您應該學會如何儘快完成這個任務。 – jmcilhinney

+0

謝謝......現在我知道我在做什麼錯了。非常感謝 。 – veenu

回答

0
Private Sub chkLoop_CheckedChanged(sender As Object, e As EventArgs) Handles chkLoop.CheckedChanged 
    If chkLoop.Checked Then 
     ... 
     intValue1 = nudX4.Value 
     intValue2 = nudY4.Value 
    ElseIf chkLoop.CheckState = CheckState.Unchecked Then 
     nudX4.Value = intValue1 
     nudY4.Value = intValue2 
     ...