I'm not sure you understand what static means, static means that it belongs to the CLASS not an INSTANCE of the class. Possibly a better solution to your problem would be to create an instance method which set the text.
// private variable
private TextBox textbox2;
private void Form1_Load(object sender, EventArgs e)
{
// refers to private instance variable
textbox2 = new TextBox();
textbox2.Text = "A";
}
private void gettext()
{
// refers to private instance variable
textbox2.Text = "B";
}
If you're having difficulty understanding static
, odds are you don't need to use it. Static members are available to all instances of a class but don't belong to any of them, which means static methods cannot access private members.