public double? value1 = null ;//獲取運(yùn)算符前的數(shù)值
public double? value2 = null ;//獲取運(yùn)算符前的數(shù)值
public type caltype=type .none ;//獲取運(yùn)算符
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”按鈕的單擊事件
一共有十個這樣的數(shù)字鍵按鈕單擊事件
是不是覺得這樣寫很麻煩,于是就有了按鈕注冊事件。下面是我后面下的一段代碼:
代碼如下:
public double? value1 = null ;//獲取運(yùn)算符前的數(shù)值
public double? value2 = null ;//獲取運(yùn)算符后的數(shù)值
public type caltype=type .none ;//獲取運(yùn)算符
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上面,從而動態(tài)注冊按鈕事件
}
private void btnvalue_Click(object sender, EventArgs e)
{
Button btn =(Button)sender ;
//實(shí)例化按鈕,從而獲取當(dāng)前單擊按鈕的值
if (value1 == null)
{
value1 = Convert.ToDouble(btn.Text);
}
else
{
value2 = Convert.ToDouble(btn.Text);
}
this.txtvalue.Text = btn.Text;
}
是不是覺的比以前簡單多了。。。(要源碼的話請聯(lián)系我 QQ:342468914)聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com