views:

981

answers:

2

Hi all,

I'm working on a program that is form based but I have been asked to add some command line support, this works fine apart from the form flashes up and closes down when running from the command line. Is there anyway to hide the form whilst the command line is running? Some code does refer to controls so the gui would need to be accessible but not visible, is this workable?

Thanks

+2  A: 

In your Main method you can create the form such as:

main = new MainForm();

then do any command line processing required.

When not in command line mode simply call:

Application.Run(main);
benPearce
A: 

There are a few apps that I've run across which have this behavior right from the constructor of the form class. Basically their constructor handles the command line arguments and the calls an Environment.Exit(0) when the process for the command line args has completed successfully. Calling Environment.Exit before the constructor of the form class complete effectively prevents the form from ever showing up.

Having said that, it's error prone, and I would say that it's been to not have the form class as the startup of the app. Use another class instead which can instantiate and show the form as needed, or process the command line arguments instead.

Jeff Schumacher