【发布时间】:2013-02-26 11:58:10
【问题描述】:
我创建了一个文本框并希望在静态方法中引用它。我怎样才能做到这一点? 这是我的代码
private void Form1_Load(object sender, EventArgs e)
{
TextBox textbox2 = new TextBox();
textbox2.Text = "A";
}
static void gettext()
{
textbox2.Text = "B"; //here is my problem
}
【问题讨论】:
-
你不能。你需要一个对象。
-
另请注意,Form1_Load 中的代码 textbox2 是方法的本地,而不是类的本地。在 Form1_Load 之外定义文本框 textbox2
-
请告诉我怎么做。我是 C# 新手。
-
谁能告诉我如何在我的静态方法中对 texbox2 进行对象引用?