views:

331

answers:

3

Hi, could you please help me with this one? I'm trying to capture Tab key in Windows Forms application and do a custom action on it.

I have a Form with several listViews and buttons, I've set Form's KeyPreview property to true and when I press any other key than tab, my KeyDown event handler does get called. But that's not true with the Tab key - I don't receive WM_KEYDOWN message even in WndProc. Do I need to set each control inside my form - its TabStop property - to false? There must be a more ellegant way that that. Thanks.

+2  A: 

will this help you?

Veer
Axarydax
+1  A: 

This is the C# code similar to the VB code given above link...

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (keyData == Keys.Tab)
        {
            //your code
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }

Hope this helps...

Ram
A: 

Do not know about C#, but for C++: TAB key processed in PretranslateMeggase of CDialog class. More precisely in CDialog::PretranslateMessage the IsDialogMessage is called. So in MSVC++ to proceess TAB you should override PretranslateMessage. I believe in C# should be something similar.

Also you can look at keyboard hooks.

VitalyVal