我弄了一个加减乘除的计算器,,但是只能有鼠标 (我们只教了单机事件) 然后我想 让它可以用键盘操作
下面是代码
[C#] 纯文本查看 复制代码 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
string t;
string a, b, c;
double q, w;
double f;
bool z, x, s, v;
string i;
int r = 0;
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{//文本框内容加上按钮标题
textBox1.Text += button1.Text;
}
private void button7_Click(object sender, EventArgs e)
{//文本框内容加上按钮标题
textBox1.Text += button7.Text;
}
private void button4_Click(object sender, EventArgs e)
{//文本框内容加上按钮标题
textBox1.Text += button4.Text;
}
private void button6_Click(object sender, EventArgs e)
{//文本框内容加上按钮标题
textBox1.Text += button6.Text;
}
private void button12_Click(object sender, EventArgs e)
{//文本框内容加上按钮标题
textBox1.Text += button12.Text;
}
private void button11_Click(object sender, EventArgs e)
{//文本框内容加上按钮标题
textBox1.Text += button11.Text;
}
private void button10_Click(object sender, EventArgs e)
{//文本框内容加上按钮标题
textBox1.Text += button10.Text;
}
private void button16_Click(object sender, EventArgs e)
{//文本框内容加上按钮标题
textBox1.Text += button16.Text;
}
private void button15_Click(object sender, EventArgs e)
{//文本框内容加上按钮标题
textBox1.Text += button15.Text;
}
private void button14_Click(object sender, EventArgs e)
{//文本框内容加上按钮标题
textBox1.Text += button14.Text;
}
private void button17_Click(object sender, EventArgs e)
{//文本框内容为空
textBox1.Text = "";
}
private void button8_Click(object sender, EventArgs e)
{//文本框内容加上按钮标题
textBox1.Text += button8.Text;
}
private void button13_Click(object sender, EventArgs e)
{//+号
//变量a等于文本框
a = textBox1.Text;
if (a == "")
{
textBox1.Text = "0";
a = textBox1.Text;
}
q = Convert.ToDouble(a);
textBox1.Text = "";
z = true;
x = false;
s = false;
v = false;
}
private void button9_Click(object sender, EventArgs e)
{ // -号
//变量a等于文本框内容
a = textBox1.Text;
if (a == "")
{
textBox1.Text = "0";
a = textBox1.Text;
}
//变量q等于变量a
q = Convert.ToDouble(a);
//文本框内容为空
textBox1.Text = "";
//bool变量x为真
x = true;
z = false;
s = false;
v = false;
}
private void button3_Click(object sender, EventArgs e)
{//*号
a = textBox1.Text;
if (a == "")
{
textBox1.Text = "0";
a = textBox1.Text;
}
q = Convert.ToDouble(a);
textBox1.Text = "";
s = true;
z = false;
x = false;
v = false;
}
private void button5_Click(object sender, EventArgs e)
{// 除号
a = textBox1.Text;
if (a == "")
{
textBox1.Text = "0";
a = textBox1.Text;
}
q = Convert.ToDouble(a);
textBox1.Text = "";
v = true;
z = false;
x = false;
s = false;
}
private void button18_Click(object sender, EventArgs e)
{//如果bool变量z为真
if (z == true)
{
b = textBox1.Text;
if (b == "")
{
textBox1.Text = "0";
b = textBox1.Text;
}
w = Convert.ToDouble(b);
f = q + w;
textBox1.Text = Convert.ToString(f);
}
else if (x == true)
{
b = textBox1.Text;
if (b == "")
{
textBox1.Text = "0";
b = textBox1.Text;
}
w = Convert.ToDouble(b);
f = q - w;
textBox1.Text = Convert.ToString(f);
}
else if (s == true)
{
b = textBox1.Text;
if (b == "")
{
textBox1.Text = "0";
b = textBox1.Text;
}
w = Convert.ToDouble(b);
f = q * w;
textBox1.Text = Convert.ToString(f);
}
else
{
b = textBox1.Text;
if (b == "")
{
textBox1.Text = "0";
b = textBox1.Text;
}
w = Convert.ToDouble(b);
f = q / w;
textBox1.Text = Convert.ToString(f);
}
}
}
}
|