0

winfor アプリケーションでいくつかのグラフィックを移動したいと考えています。これを行うには、いずれかのカーソル キーが押されているかどうかを知る必要があります。ProcessCmdKey をオーバーライドしようとしましたが、成功しませんでした。

これを実装するためのヒント/アイデアはありますか?

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    switch (keyData)
    {
        case Keys.Left:
            // while Left is down
            // call this method repeadetdly
            buttonGoLeft();
            // when key is up stop calling this method
            // and check for other keys
            return true;

         //Other cases
     }
  }
4

1 に答える 1

1

これはうまくいきます!

using System.Windows.Forms;

namespace WindowsFormsApplication5
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            KeyPreview = true;
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
                case Keys.Left:
                    // while Left is down
                    // call this method repeadetdly
                    MessageBox.Show("its left", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    // when key is up stop calling this method
                    // and check for other keys
                    return true;

                default:
                    return false;
            }
        }
    }
}
于 2012-12-17T14:34:12.523 に答える