2016-05-12 43 views
0

我有一个函数,其中特定值不允许超过另一个值。但是,如果是这样,我想保留旧文本框中的值,这些文本框在更改之前就已经存在了。我怎么做?如果不符合条件,则保留文本框中的旧值

Private Sub TextBox20_TextChanged(sender As Object, e As EventArgs) Handles TextBox20.TextChanged 

    'PREVENTS THE USER FROM APPLYING A THICKNESS GREATER THAN THE HIGHT AND LENGTH OF THE EXTRUSION SPECIFIDE...S 
    If TextBox20.Text >= ((TextBox17.Text/2) + 1) Or TextBox20.Text >= ((TextBox18.Text/2) + 1) Then 
     MessageBox.Show("CAUTION!" & vbCrLf & vbCrLf & "The material thickness cannot exceed the" & vbCrLf & "total height or width of the extrussion " & vbCrLf & "Either reduce the material thickness or increase the total " & vbCrLf & "height and or width of the extrusion", "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) 
    End If 
    'PREVENTS THE USER FROM APPLYING A THICKNESS GREATER THAN THE HIGHT AND LENGTH OF THE EXTRUSION SPECIFIDE...E 

End Sub 

回答

2

您可以使用验证事件,并设置e.Cancel = true来防止出现文本变化 -

Private Sub TextBox20_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox20.Validating 
     If {your logic} Then 
      'messagebox 
      e.Cancel = true 
      Return 
     End If 
    End Sub