我有一个函数,其中特定值不允许超过另一个值。但是,如果确实如此,我想在更改之前保留TextBox中的旧值。我该怎么做?
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
答案 0 :(得分:2)
您可以使用Validating事件并设置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