How to pass args command line parameter from Program.cs to Form1.cs ?

  • Thread starter Thread starter Pia Stevens
  • Start date Start date
P

Pia Stevens

For a GUI CSharp program I could define command line parameter as well
by declaring them in Main():

static void Main(string[] args)

But how do I pass them easily to Form1 ?

Or should I declare them in Program.cs and access them from Form1.cs ?

Pia
 
For a GUI CSharp program I could define command line parameter as well
by declaring them in Main():

static void Main(string[] args)

But how do I pass them easily to Form1 ?

Or should I declare them in Program.cs and access them from Form1.cs ?

As with most computer algorithms, the task can be accomplished in a
number of ways. You can declare global variables in the main program
and assign the command line arguments to them. Or you can make the
properties in the form class and initialize them before showing the
form.
 
Pia Stevens said:
For a GUI CSharp program I could define command line parameter as well
by declaring them in Main():

static void Main(string[] args)

But how do I pass them easily to Form1 ?

Or should I declare them in Program.cs and access them from Form1.cs ?

It's always worth thinking about forms and other GUI classes as just
like normal classes - because they are.

How would you pass parameters from one class to another normally? You
could use a constructor which takes parameters, or possibly have a
method or property on the class and provide them after construction.

These options are available for forms just as for any other class.
 
Back
Top