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均调试通过
温馨提示:内容为网友见解,仅供参考