Windows Develop Bookmark and Share   
 index > Windows Forms General > Workaround Needed for No Tab KeyChar
 

Workaround Needed for No Tab KeyChar

Per Microsoft, I cannot get or set the KeyChar value for the TAB key.If the TAB or ENTER key is pressed then I need to call a method. Is there a way of either detecting the TAB key or turning it off? I do not want to write a method for each control.leave.

private void tabControl_ProcA_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Tab || e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
calculateArea(this.ActiveControl);
this.SelectNextControl(this.ActiveControl, true, true, true, false);
}
}

Thanks, cj

polymorphicx  Tuesday, October 31, 2006 5:17 PM
The Tab and Enter keys are special, you need to catch them early before the form starts using them. Add this code to your form:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (keyData == Keys.Tab) {
// Do your stuff, comment out the next line if the Tab should still be handled
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}

nobugz  Wednesday, November 01, 2006 12:38 PM
The Tab and Enter keys are special, you need to catch them early before the form starts using them. Add this code to your form:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (keyData == Keys.Tab) {
// Do your stuff, comment out the next line if the Tab should still be handled
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}

nobugz  Wednesday, November 01, 2006 12:38 PM

You can use google to search for other answers

Custom Search

More Threads

• How do I get the current pixel's color from anywhere on the user's screen? .. By VB.NET
• C# 2008 Toolstrip Menu Question
• is there an api to get the mac address of a machine
• Finding a Control in the GAC
• send status from object running in backgroundworker to the form
• ComboBox works in DataGridView but not as standalone
• PropertyPages for UserControls
• Stopping Index Change on ListView
• browser in c#
• Ping command in Winforms