Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C#: How to control the behavior of the TAB Key ???

Status
Not open for further replies.

salooo

Programmer
Sep 11, 2003
30
US
Hello,
I am using C# on the VS.NET platform. I have this application that requires the TAB key to function in a different manner.
I want to know how I can control the behavior of the TAB key in my Application???
If there is no way to control the TAB key, is it possible to disable it completely in my application ?????

Any help would be greatly appreciated.

Thanks.
 
Hi,
You can control any key in your application. You have to override some handlers and take the action you desire when a key si pressed.
See Control.KeyPress Event() , GroupBox.KeyPress(), Panel.keyPress(), Label.KeyPress() etc..
Depending on waht is doing your application see also:
Control.ProcessKeyEventArgs(),
Control.ProcessKeyPreview() for TabControl, DataGrid, Form objects.
You should look also to to Control.OnKeyPress(), OnKeyDown(), OnKeyUp()when you trap the key value.

-obi-

 
I have a similar problem. I need to handle a tab keypress within a TreeView control only, but make it operate as usual outside of the control.

I have tried several things without success. Namely, I created a class that inherits from TreeView. I tried overriding the KeyDown event of the TreeView control, but the KeyDown event is never fired when pressing a tab. It works for other keys, just not the tab. I read later that I needed to have an override of IsInputChar in my class. The override code for IsInputChar is returns true if a tab was pressed, so that the KeyDown event gets fired. But, this method is never called when pressing a tab! Again, other keys cause it to be called, but not the tab key.

After reading more documentation, I tried a different method later, which involves putting a similar KeyDown event handler and IsInputChar inside the form class that contains my tree control. Inside this handler, I test to see if the tree control contains focus, and if so, I call the feature code and set the KeyEventArgs.handled to true. But, neither this handler, nor the IsInputChar are called when pressing a tab.

It seems that the tab character is so special that it is getting handled deeper in the framework than we can trap. The documentation says it should work, but it doesn't.

If anybody has any ideas, please help!!
 
Sorry, I forgot to mention that handling keystrokes at the form level also requires setting the form's KeyPreview property to true so that it gets first shot at key-handling.

But, like I said before, it doesn't work for the tab key.
 
Hello Steve,

Yeah man this issue is a real pain in the butt. I tried to change the "tab stop" property of every control on my form to False, that's the only way your IsInputChar will produce a result telling you that the tab key was pressed. For now I have changed this property for all the controls on the form to False. If you find a solution then please post it.

Thanks and good luck.

Chow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top