在将键盘输入到编辑框中之前,如何截取键盘输入?我有:
<Window x:Class="X.MainWindow"
KeyDown="Window_KeyDown"
>
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Add)
return;
}//Window_KeyDown
按下键盘的数字部分上的“ +”按钮被检测到。还将“ +”放入我的一个编辑框中。如何防止这种情况发生?
在将密钥发送到文本框之前,您已经对其进行了拦截。
现在,设定
e.Handled = true;
这样事件就不会一直传播到文本框
http://msdn.microsoft.com/zh-CN/library/system.windows.routedeventargs.handled(v=vs.110).aspx
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Add)
{
e.Handled = true; // Prevents the event from propagating further.
return;
}
}//Window_KeyDown
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句