How to use arrow keys in Form
This article mainly introduces "how to use the arrow keys in Form". In daily operation, I believe many people have doubts about how to use the arrow keys in Form. Xiaobian consulted all kinds of information and sorted out simple and easy operation methods. I hope to help you answer the doubts about "how to use the arrow keys in Form"! Next, please follow the small series to learn together!
In fact, it's very simple. I used hook functions to solve it before. In fact, it's not necessary at all. Rewrite the Form method.
const int WM_SYSKEYDOWN=260;const int WM_KEYDOWN=256;protected override bool ProcessCmdKey(ref Message msg,Keys keyData){if ((msg.Msg==WM_KEYDOWN)||(msg.Msg==WM_SYSKEYDOWN)){switch (keyData){case Keys.Up:MessageBox.Show("up");break;case Keys.Down:MessageBox.Show("down");break;case Keys.Left:MessageBox.Show("left");break;case Keys.Right:MessageBox.Show("right");break;}}return true;}
Supplement: After experiments, this method can only extract KEYDOWN information, while KEYUP information is "eaten", so some things that need KEYUP events cannot be done.
Finally found a class in CodeProject to handle this, very convenient: www.codeproject.com/KB/cs/globalhook.aspx
At this point, the study of "how to use the arrow keys in Form" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!