如何确定按下的键是下划线还是减号? C#
How to determine if Pressed key is Underscore Or Minus? C#
问题是下划线和减号的键值都是 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");
}
}
如果这是一个 WinForms 项目,请使用 KeyPress
事件而不是 KeyDown
事件:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == '-')
{
MessageBox.Show("Minus");
}
if (e.KeyChar == '_')
{
MessageBox.Show("Underscore");
}
}
问题是下划线和减号的键值都是 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");
}
}
如果这是一个 WinForms 项目,请使用 KeyPress
事件而不是 KeyDown
事件:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == '-')
{
MessageBox.Show("Minus");
}
if (e.KeyChar == '_')
{
MessageBox.Show("Underscore");
}
}