C#通过'W''S''A''D'移动控件

首先设置窗体KeyPreview属性为True

 使用窗体KeyPress事件

 private void FormMain_KeyPress(object sender, KeyPressEventArgs e)
        {
            switch (e.KeyChar)
            {
                case 'w':
                case 'W':
                    button1.Top--;
                    break;
                case 's':
                case 'S':
                    button1.Top++;
                    break;
                case 'a':
                case'A':
                    button1.Left--;      
                    break;
                case 'd':
                case 'D':
                    button1.Left++;
                    break;
                default:
                    break;
            }
        }

  

原文地址:https://www.cnblogs.com/Luck1996/p/11914464.html