日期:2014-05-18 浏览次数:21516 次
// 构造函数里 this.button1.Text = "0"; // 点击事件 private void button1_Click(object sender, EventArgs e) { this.button1.Text = (int.Parse(this.button1.Text) + 1).ToString(); }
------解决方案--------------------
设置一个全局变量咯,
int click_count=0;
private void button1_Click(object sender, EventArgs e)
{
click_count++;
}
private void button2_Click(object sender, EventArgs e)
{
click_count=0
}
------解决方案--------------------
static int count = 0; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { count++; } private void button2_Click(object sender, EventArgs e) { count = 0; } private void button3_Click(object sender, EventArgs e) { MessageBox.Show(count.ToString()); }
------解决方案--------------------
不显示在按钮上
// 全局变量 private int clickCount = 0; // 递增按钮事件 private void button1_Click(object sender, EventArgs e) { ++clickCount; } // 清空按钮事件 private void button1_Click(object sender, EventArgs e) { clickCount = 0; }
------解决方案--------------------
public Form1() { InitializeComponent(); button1.Tag = 0; } private void button1_Click(object sender, EventArgs e) { button1.Tag = Convert.ToInt32(button1.Tag) + 1; } private void button2_Click(object sender, EventArgs e) { button1.Tag = 0; } private void button3_Click(object sender, EventArgs e) { MessageBox.Show(button1.Tag.ToString()); }