Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I prevent a TextBox from performing validation when the user clicks on the Cancel button?

Say textBox1 and canelButton and the control names, then this is how you could do this:

[C#]

using System.ComponentModel;

// Handler to the Validating event of the TextBox. 
private void TextBox_Validating( object sender, CancelEventArgs e ) 
{ 
  // Do this only when the cancel button is not clicked. 
  if ( !cancelButton.Focused ) 
    if ( invalidState ) 
      e.Cancel = true; 
} 

Contributed from George Shepherd's Windows Forms FAQ



Page view counter