复制代码 代码如下:
public double? value1 = null ;//获取运算符前的数值
public double? value2 = null ;//获取运算符前的数值
public type caltype=type .none ;//获取运算符
private void btnvalue1_Click(object sender, EventArgs e)
{
if (value1 == null)
{
value1 = Convert.ToDouble(btnvalue1.Text);
}
else
{
value2 = Convert.ToDouble(btnvalue1.Text);
}
this.txtvalue.Text = btnvalue1.Text;
}“1”按钮的单击事件
复制代码 代码如下:
public double? value1 = null ;//获取运算符前的数值
public double? value2 = null ;//获取运算符后的数值
public type caltype=type .none ;//获取运算符
private void Form1_Load(object sender, EventArgs e)
{
btnvalue0.Click += new EventHandler(btnvalue_Click);
btnvalue1.Click += new EventHandler(btnvalue_Click);
btnvalue2.Click += new EventHandler(btnvalue_Click);
btnvalue3.Click += new EventHandler(btnvalue_Click);
btnvalue4.Click += new EventHandler(btnvalue_Click);
btnvalue5.Click += new EventHandler(btnvalue_Click);
btnvalue6.Click += new EventHandler(btnvalue_Click);
btnvalue7.Click += new EventHandler(btnvalue_Click);
btnvalue8.Click += new EventHandler(btnvalue_Click);
btnvalue9.Click += new EventHandler(btnvalue_Click);
//通过EventHandler将按钮控件的Click事件
绑定到 btnvalue_Click上面,从而动态注册按钮事件
}
private void btnvalue_Click(object sender, EventArgs e)
{
Button btn =(Button)sender ;
//实例化按钮,从而获取当前单击按钮的值
if (value1 == null)
{
value1 = Convert.ToDouble(btn.Text);
}
else
{
value2 = Convert.ToDouble(btn.Text);
}
this.txtvalue.Text = btn.Text;
}
新闻热点
疑难解答
图片精选