如何停止使用DropDownList的上/下键 [英] How to Stop Working of up/down key for DropDownList
问题描述
大家好,
我在一个窗口应用程序中工作,我有一个DropDownlist控件。当我把注意力集中在下拉列表并使用上/下键时,下拉键值就会发生变化...
我应该停止这个吗?
如果可能的话怎么样?请尽可能帮助我....
谢谢和问候
JD
你不应该这样做。因为这是默认行为。
如果有人想用键盘填写表格,那么他/她会做什么?
只需检查按下的键下拉列表事件例如如下:
受保护 覆盖 void OnPreviewKeyDown(KeyEventArgs e)
{
if (IsReadOnly)
{
if (e.Key == Key.Down || e.Key == Key .Up)
{
e.Handled = true ;
return ; // 不要调用基类方法OnPreviewKeyDown()
}
}
base .OnPreviewKeyDown(e);
}
引用:这是对的,但我想要为另一个控件创建一个快捷键Ctrl +向上箭头,但它不起作用,它只能作为向上箭头键并更改下拉列表的值
您需要将表单的KeyPreview属性设置为true
此。 KeyPreview = true ;
通过设置上面的属性表单将收到关键事件在事件传递给具有焦点的控件之前。
Hello to all,
I am working in one window application , I have one DropDownlist control in it. when i set focus on dropdown and use up/down key value of dropdown is change...
Should i stop this?
If possible than how ? please help me if possible this thing ....
Thanks and Regards
JD解决方案You should not stop this. Because this is the default behaviour.
If somebody wants to fill the form with keyboards only, then what would he/she do?
Just check the key pressed event for dropdownlist for example given below:
protected override void OnPreviewKeyDown(KeyEventArgs e) { if (IsReadOnly) { if (e.Key == Key.Down || e.Key == Key.Up) { e.Handled = true; return; // do not call the base class method OnPreviewKeyDown() } } base.OnPreviewKeyDown(e); }
Quote:That's right but i want to create one shortcut key Ctrl + Up Arrow for another control but it's not work and it's only get as a up Arrow key and change the value of dropdownlist
you need to set form's KeyPreview property to true
this.KeyPreview = true;
by setting above property form will receive key events before the event is passed to the control that has focus.
这篇关于如何停止使用DropDownList的上/下键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!