C#写计算器,键盘keypress关联鼠标click点击事件,只响应数字按键,无法响应加,减,乘,除,小数点按键.
C#写计算器,键盘keypress关联鼠标click点击事件,只响应数字按键,无法响应加,减,乘,除,小数点按键.
我重载了button1_Click(sender, e,inputText)和buttonAdd_Click(sender, e,inputText)事件,以获取所按键字符,
数字按键和小数点按键都调用button1_Click()
运算符号调用buttonAdd_Click()
求大大给出详细原因,部分代码如下:
private void Form1_KeyPress(object sender, KeyPressEventArgs e) { switch ((Keys)e.KeyChar) { case Keys.Add: case Keys.Subtract: case Keys.Multiply: case Keys.Divide: inputText = e.KeyChar.ToString(); buttonAdd_Click(sender, e, inputText); break; case Keys.D1: case Keys.D2: case Keys.D3: case Keys.D4: case Keys.D5: case Keys.D6: case Keys.D7: case Keys.D8: case Keys.D9: case Keys.D0: case Keys.Decimal: inputText = e.KeyChar.ToString(); button1_Click(sender, e,inputText); break; } }