Get parameters in Windows Forms App
-
Hi. How can I read command line parameters used to call a Windows Form Application? I use VS2005 to create a new Windows application. The autogenerated Program.cs fle looks like this:
.... static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainFrm()); } } ....
Shouldn't the Main method header include a parameter for arguments? Can I add it by hand? Are there any other options? Thanks. -
Hi. How can I read command line parameters used to call a Windows Form Application? I use VS2005 to create a new Windows application. The autogenerated Program.cs fle looks like this:
.... static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainFrm()); } } ....
Shouldn't the Main method header include a parameter for arguments? Can I add it by hand? Are there any other options? Thanks.feel free to add the arguments to Main function. This wil stil work with windows forms eg. static void Main(string[] args)
-
feel free to add the arguments to Main function. This wil stil work with windows forms eg. static void Main(string[] args)
You don't need to do that, you can just call:
string[] args = Environment.GetCommandLineArgs();
FYI, args[0] is the app file name.
-
You don't need to do that, you can just call:
string[] args = Environment.GetCommandLineArgs();
FYI, args[0] is the app file name.
Thanks for the tip.