如何从表单加载变为动作?

时间:2011-09-04 13:35:41

标签: c# c#-4.0

private void showCategory_Load(object sender, EventArgs e)
{
   string categoryId = "100"
}

private void button1_Click(object sender, EventArgs e)
{
   textBox1.Text = categoryId;
}

如何将表单加载中的字符串categoryId传递给按钮单击? 谢谢。

1 个答案:

答案 0 :(得分:2)

如果是Windows Forms应用程序,而不是在类级别使用变量,而不是在函数

public partial class showCategory : Form
{
    string categoryId = null;

    private void showCategory_Load(object sender, EventArgs e)
    {
        this.categoryId = "100";
    }

    private void button1_Click(object sender, EventArgs e)
    {
        textBox1.Text = this.categoryId;
    }
}

如果是Web应用程序 - 存储一些状态callection的值:ViewState,Session,HiddenField等等。