7.1 How can I prevent a control from getting a particular keystroke?


You can handle the control's KeyPress event and indicate the key has been handled. Below is code that prevents a TextBox from getting an 'A' and the return key.

private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
     if(e.KeyChar == (char)13 || e.KeyChar == 'A')
          e.Handled = true;
}

© 2001-2010 Copyright Syncfusion Inc. All rights reserved.  |  Privacy Policy  |  Contact  |  Sitemap