I need to change a button text using an static function.
static string[] ARRay = new string[10];
[STAThread]
static void Main()
{
string[] args = Environment.GetCommandLineArgs();
for (int i = 1; i != args.Length; ++i)
{
command(i.ToString());
ARRay[0] = i.ToString();
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
static void command(string line)
{
button1.Text = ARRay[0]; // here error
}
First of all,
button1seems to be the member of theForm Form1. You need to first store theForm1instance in theMainmethod by first declaring astaticmember:and then creating and passing that instance to
Runmethod ofApplication:After you do this, you will have two options:
1. If
button1is apublicButton, you can use this line in yourcommandmethod:Or 2. You can declare a
publicmethod inForm1classto update thebutton1.Text.