如何捕获方向键

在窗体中添加如下的重写方法来处理按键的信息:

/*键盘事件*/
        protected override bool ProcessDialogKey(Keys keyData)
        {
            switch (keyData)
            {
                case Keys.Tab: MessageBox.Show(keyData.ToString());
                    break;
                case Keys.Left: MessageBox.Show(keyData.ToString());
                    break;
                case Keys.Right: MessageBox.Show(keyData.ToString());
                    break;
            }
            if (keyData == Keys.Up || keyData == Keys.Down || keyData == Keys.Left || keyData == Keys.Right)
                return false;
            else
                return base.ProcessDialogKey(keyData);
        }

posted @ 2007-05-30 18:16  小y  阅读(862)  评论(0编辑  收藏  举报