Say textBox1 and cancelButton and the control names, then this is how you could do this:
[C#]
// Handler to the Validating event of the TextBox.
private void TextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!this.cancelButton.Focused)
{
// Do this only when the cancel button is not clicked.
if(invalidState)
e.Cancel = true;
}
}
[VB.Net]
’ Handler to the Validating event of the TextBox.
Private Sub TextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
If Not Me.cancelButton.Focused Then
’ Do this only when the cancel button is not clicked.
If invalidState Then
e.Cancel = True
End If
End If
End Sub
Share with