发布网友 发布时间:2024-10-23 19:16
共3个回答
热心网友 时间:2024-10-31 14:41
winform还是asp.net
对于asp.net
protected void Button1_Click(object sender, EventArgs e)
{
int hits;
if (ViewState["hits"] == null)
{
hits = 0;
}
else
{
hits = (int)ViewState["hits"];
}
hits++;
ViewState["hits"] = hits;
this.TextBox1.Text = hits.ToString();
}
对于winform
public int i;
private void button1_Click(object sender, EventArgs e)
{
i++;
this.textBox1.Text = "单击了"+i.ToString()+"次";
}
private void Form1_Load(object sender, EventArgs e)
{
i = 0;
}
以上代码vs 2005 vs 2008均调试通过
热心网友 时间:2024-10-31 14:48
2楼正解
热心网友 时间:2024-10-31 14:47
用一个静态变量保存一下就行了.static int total = 0; 然后在单击事件里写上:total++;MessageBox.show(total);