Thursday, February 09, 2012
 
 View Article   
02

In a windows form I needed to detect if the tab key was pressed, but Tab keys are “eaten” by windows, creating a KeyPress event on the textbox won’t do it.

But I fond the ProcessCmdKey you can put on the form, the code below did it:



 

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)

{

if(textBox1.Focused == true) // do the textbox have focus?

{

const int WM_KEYDOWN = 0x100;

const int WM_SYSKEYDOWN = 0x104;

if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))

{

if(keyData == Keys.Tab)

{

MessageBox.Show("tab key pressed inside textbox1");

return true; // I have processed the key

}

}

}

return false; // Key not prcessed by me

}

Posted in: Programming Tips

Post Rating

Comments

jonathan
# jonathan
Wednesday, August 23, 2006 2:52 PM
perfect!!!!!

Post Comment

Only registered users may post comments.
Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement