我想覆盖一个组合框,这样可以通过键盘上的按键来选择它在列表中的位置。
示例:
ComboBoxMonths
- Jan
- Feb
- Mar
- Apr
- May
- Jun
. . .
当'J'被按下 Jan 时,'F' 'Feb', ....
我希望像
那样使用它 按 1 然后 Jan ,
2 2 等
有可能吗?如果是,我怎样才能实现这一目标?
答案 0 :(得分:0)
只有在将组合设置为DropDownList时才能正常工作,这在您的示例中是有意义的。它也只涵盖1-9。如果要处理多个数字,则需要更多带定时器的逻辑。
public class MyComboBox : ComboBox
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
var index = e.KeyChar - '1';
if( index >= 0 && index < this.Items.Count )
this.SelectedIndex = index;
base.OnKeyPress(e);
}
}