Arp*_*pta 2 c# keyboard-events winforms
问题是下划线和减号的键值都是 189,键码是 Keys.OemMinus。所以我无法检查按下的键是下划线还是减号。请帮忙。
private void Some_KeyDown(object sender, KeyEventArgs e)
{
if(Pressed key is minus/dash)
{
MessageBox.Show("minus");
}
if(pressed key is underscore)
{
MessageBox.Show("underscore");
}
}
Run Code Online (Sandbox Code Playgroud)
如果这是一个 WinForms 项目,请使用KeyPress事件而不是KeyDown事件:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == '-')
{
MessageBox.Show("Minus");
}
if (e.KeyChar == '_')
{
MessageBox.Show("Underscore");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1942 次 |
| 最近记录: |