计算器按钮事件怎么做?
计算器除了界面以外怎么做?就是按下按钮时,在textbox中显示出相应的数字 --------------------编程问答-------------------- private void btnN1_Click(object sender, EventArgs e)
{
this.txt.Text += btnN1.Text;
}
给每个数字按钮写上类似的代码 --------------------编程问答-------------------- 窗体里定义
private void ShowNum(object sender, EventArgs e)
{
textBox1.Text = ((Button)sender).Text;
}
designer.cs里修改
(X为0-9)
this.buttonX.Click += new System.EventHandler(this.ShowNum); --------------------编程问答--------------------
TextBox _TextBox = null;
public TextBox TextBox
{
get { return _TextBox; }
set
{
if (_TextBox != value)
{
_TextBox = value;
}
}
}
private void btnOne_Click(object sender, EventArgs e)
{
if (this.TextBox != null)
{
this.TextBox.Text += btnOne.Text;
this.TextBox.Focus();
this.TextBox.SelectionStart=this.TextBox.Text.Length;
}
}
private void txtBox(object sender, EventArgs e)
{
textBox.Text = ((txtBox)sender).Text;
}
--------------------编程问答-------------------- private void txtBox_GetFocus(object sender, EventArgs e)
{
textBox.Text = ((txtBox)sender).Text;
}
少打了必个字 --------------------编程问答-------------------- 楼上的好像都不太对吧 单个按钮事件太多的话 不行 再说每次按按钮,text应该追加才对,应该用按钮继承事件和数组追加来做吧
补充:.NET技术 , C#