CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    153

    Capture Tab- and Arrow Keys

    Hi there,

    i'm having a little problem with capturing Tab- and Arrow Key Events.

    I have a Form with some controls on it.

    Now i set the focus to one control ( something inherited from UserControl ).
    Now the problem is, that in the Key-Down event of this control i can handle everything, but the tab-key and the arrow-keys.

    I think because those are handled by the system ( to focus the next control in the tab order ).

    Do i have any chance to handel them anyway?

    Hints are very welcome,
    Thanx Matze

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Capture Tab- and Arrow Keys

    You can override the ProcessCmdKey method of your control to process the keys that are otherwise used bythe System (like TAB, UP, Down, etc). In your user control class, you will need to override this method like this
    Code:
    		protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    		{
    			const int WM_KEYDOWN = 0x100;
    			const int WM_SYSKEYDOWN = 0x104;
    
    			if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
    			{
    				switch(keyData)
    				{
    					case Keys.Down:
    						MessageBox.Show("Down Arrow Captured");
    						break;
    
    					case Keys.Up:
    						MessageBox.Show("Up Arrow Captured");
    						break;
    
    					case Keys.Tab:
    						MessageBox.Show("Tab Key Captured");
    						break;					
    				}
    			}
    			return true;				
    		}

  3. #3
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    153

    Re: Capture Tab- and Arrow Keys

    Hi Shuja Ali,

    ... Perfect. It works.
    Thank you very much.

    Greetings,
    Matze

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured