Vb.net 如果不符合条件,则在文本框中保留旧值
我有一个函数,其中一个特定值不允许超过另一个值。但是,如果是这样的话,我希望保留在文本框中的旧值,在进行更改之前就在那里。我该怎么做Vb.net 如果不符合条件,则在文本框中保留旧值,vb.net,math,textbox,Vb.net,Math,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 O
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
您可以使用验证事件并设置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
您可以使用验证事件并设置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