Disable Tab Key

  • Thread starter Thread starter Gene Vital
  • Start date Start date
G

Gene Vital

C#

I am trying to figure out how to disable the Tab key in a TextBox.I need
to prevent the user from leaving the TextBox unless the data was entered
correctly, any pointers?
 
Hi Gene,
you can derive your own textbox class from the
System.Windows.Forms.TextBox and then override the ProcessCmdKey method to
not allow the user to tab away from the control

For example:

class MyTextBox : TextBox
{
public MyTextBox() : base()
{
}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(keyData == Keys.Tab)
{
//do
nothing, so return true;
return true;
}

return base.ProcessCmdKey (ref msg, keyData);
}

}

Hope that helps
Mark R Dawson
 
Gene said:
C#

I am trying to figure out how to disable the Tab key in a TextBox.I need
to prevent the user from leaving the TextBox unless the data was entered
correctly, any pointers?

Thank you both....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top