关于c#编程计算器连接键盘的问题
在网上找了一些关于计算器连接键盘的代码,放在的form_keydown事件中,但是就是不能让此事件起作用,我的textbox窗口就是不接受数据,代码如下:switch(e...
在网上找了一些关于计算器连接键盘的代码,放在的form_keydown事件中,但是就是不能让此事件起作用,我的textbox窗口就是不接受数据,代码如下:
switch (e.KeyCode)
{
case System.Windows.Forms.Keys.NumPad1:
Buttons[1].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad2:
Buttons[2].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad3:
Buttons[3].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad4:
Buttons[4].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad5:
Buttons[5].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad6:
Buttons[6].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad7:
Buttons[7].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad8:
Buttons[8].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad9:
Buttons[9].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad0:
Buttons[0].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.Add:
YunSuanFu[1].Click += new EventHandler(buttonYunSuan_Click);
break;
case System.Windows.Forms.Keys.Subtract:
YunSuanFu[2].Click += new EventHandler(buttonYunSuan_Click);
break;
case System.Windows.Forms.Keys.Multiply:
YunSuanFu[3].Click += new EventHandler(buttonYunSuan_Click);
break;
case System.Windows.Forms.Keys.Divide:
YunSuanFu[4].Click += new EventHandler(buttonYunSuan_Click);
break;
case System.Windows.Forms.Keys.Oemplus:
buttonDeng_Click(sender, e);
break;
} 其中Buttons[1].Click += new EventHandler(button_Click);是数组的方法连接数字键的click事件,下面的是运算的click事件,还有的是等号事件,我的textbox的enable属性是false,readonly属性是true。想问一下是什么地方错了,为什么不能连接上呢?谢谢大家了
首先谢谢了,你回答了我的问题。但是在用的时候 Buttons[1].Click += new EventHandler出错,我是用数组存储界面上的button的,上句是用来连接button的click事件的,为什么这样写不行啊? 展开
switch (e.KeyCode)
{
case System.Windows.Forms.Keys.NumPad1:
Buttons[1].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad2:
Buttons[2].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad3:
Buttons[3].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad4:
Buttons[4].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad5:
Buttons[5].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad6:
Buttons[6].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad7:
Buttons[7].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad8:
Buttons[8].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad9:
Buttons[9].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.NumPad0:
Buttons[0].Click += new EventHandler(button_Click);
break;
case System.Windows.Forms.Keys.Add:
YunSuanFu[1].Click += new EventHandler(buttonYunSuan_Click);
break;
case System.Windows.Forms.Keys.Subtract:
YunSuanFu[2].Click += new EventHandler(buttonYunSuan_Click);
break;
case System.Windows.Forms.Keys.Multiply:
YunSuanFu[3].Click += new EventHandler(buttonYunSuan_Click);
break;
case System.Windows.Forms.Keys.Divide:
YunSuanFu[4].Click += new EventHandler(buttonYunSuan_Click);
break;
case System.Windows.Forms.Keys.Oemplus:
buttonDeng_Click(sender, e);
break;
} 其中Buttons[1].Click += new EventHandler(button_Click);是数组的方法连接数字键的click事件,下面的是运算的click事件,还有的是等号事件,我的textbox的enable属性是false,readonly属性是true。想问一下是什么地方错了,为什么不能连接上呢?谢谢大家了
首先谢谢了,你回答了我的问题。但是在用的时候 Buttons[1].Click += new EventHandler出错,我是用数组存储界面上的button的,上句是用来连接button的click事件的,为什么这样写不行啊? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询