我使用以下代码来处理小键盘键.
if (e.KeyCode == Keys.NumPad0 || e.KeyCode == Keys.D0)
{
MessageBox.Show("You have pressed numpad0");
}
if (e.KeyCode == Keys.NumPad1 || e.KeyCode == Keys.D1)
{
MessageBox.Show("You have pressed numpad1");
}
Run Code Online (Sandbox Code Playgroud)
还有其他小键盘键.但是我想知道如何为"+","*","/"," - ","."找到它,它位于小键盘旁边.
提前致谢
对于 "+" 、 "*" 、 "/" ,我们可以使用 KeyDown 事件,对于 "-" 、 "." ,我们可以使用 KeyDown 事件。我们可以使用 KeyPress 事件。
以下是代码:
private void button1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Add)
{
MessageBox.Show("You have Pressed '+'");
}
else if (e.KeyCode == Keys.Divide)
{
MessageBox.Show("You have Pressed '/'");
}
else if (e.KeyCode == Keys.Multiply)
{
MessageBox.Show("You have Pressed '*'");
}
}
private void button1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '.')
{
MessageBox.Show("You have pressed '.'");
}
else if (e.KeyChar == '-')
{
MessageBox.Show("You have pressed '-'");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24210 次 |
| 最近记录: |