在覆盖 ProcessCmdKey EventHandler 时跳过 KeyDown [英] Skipping KeyDown On Override ProcessCmdKey EventHandller
问题描述
我通过按下箭头键在文本框上有一个简单的增量,如下所示.
I have a simple increment on textbox by pressing down arrow key which are as below.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Down)
{
int c = int.Parse(textBox1.Text);
c++;
textBox1.Text = c.ToString();
}
}
以上适用于按双下箭头键而不是单按下箭头键.
The above works on pressing double down arrow key instead of single pressing down arrow key.
注意:上面的代码在 UserControl 上.我已经在表单 keydown EventHandler 上的简单 winform 应用程序上进行了尝试,并且效果很好.
Note: The above code is on UserControl. And I have tried it on simple winform application on form keydown EventHandller and the same is works fine.
如何克服?.
推荐答案
您需要处理之前存在的其他命令,并在处理您要查找的命令时返回.尝试将其更改为此,看看是否有帮助:
You'll need to handle other commands that existed before and return when you handle ones you are looking for. Try changing it to this and see if that helps:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (msg.WParam.ToInt32() == (int)Keys.Down)
{
int c = int.Parse(textBox1.Text);
c++;
textBox1.Text = c.ToString();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
这篇关于在覆盖 ProcessCmdKey EventHandler 时跳过 KeyDown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!