C#做一个计算器如何实现键盘输入?

如题所述

自己改一下方法名就可以了
private void txtResult_KeyPress(object sender, KeyPressEventArgs e)
{
//用于只接受键盘数字
if (e.KeyChar < '0' || e.KeyChar > '9')
{
e.Handled = true;
}
//以下是自定义控件
//主要是用于接受退格键和‘.’字符 并且此字符只能有一个
if (e.KeyChar == (char)8)
{
e.Handled = false;
}
if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf(".") < 0)
{
e.Handled = false;
}
}
温馨提示:答案为网友推荐,仅供参考
相似回答