Shift键会触发KeyDown事件,但不会触发KeyUp事件

时间:2016-03-23 18:01:18

标签: c# winforms events

我有一个没有任何控件的简单表单。 我在表单级别定义了KeyDown,KeyPress和KeyUp事件。 KeyPreview属性设置为true。代码如下:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.KeyPreview = true;
        this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
        this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);
        this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp);
    }

    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        MessageBox.Show("KeyDown.");
    }

    private void Form1_KeyPress(object sender, KeyPressEventArgs e)
    {
        MessageBox.Show("KeyPress.");
    }

    private void Form1_KeyUp(object sender, KeyEventArgs e)
    {
        MessageBox.Show("KeyUp.");
    }
}

问题是:如何强制KeyUp事件触发,因为每次按Shift键时KeyDown事件都会一直触发,但是没有触发KeyUp? 或者,有没有可靠的方法来检测Shift键释放,通过另一种方法,而不是使用KeyUp事件?

0 个答案:

没有答案
相关问题