本文介绍了按住C#WPF密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在按住键时遇到问题.只需按下按键,一切都会起作用,但是按住按键又如何呢?代码如下:
I have a problem with key held. Everything works when it's just key down but what about key holding? The code looks like this:
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down)
{
moveBall(3);
}
}
感谢您的答复.
推荐答案
WPF KeyEventArgs类具有IsRepeat属性,如果按住该键,则为true.
The WPF KeyEventArgs class has an IsRepeat property which will be true if the key is being held down.
文章示例:
// e is an instance of KeyEventArgs.
// btnIsRepeat is a Button.
if (e.IsRepeat)
{
btnIsRepeat.Background = Brushes.AliceBlue;
}
这篇关于按住C#WPF密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!