Writing an app for both WinForms and Console use

O

Oenone

I'm writing an application that I'd like to be able to use both as a Windows
Forms application, and also as a Console application.

If the app is started with no parameters, it should display its window and
allow the user to interact with it. If parameters are provided, it should
instead run as a console application and should output various information
to the standard output channel (so that the output can be redirected if
required).

By setting my app as a Windows Application, all Console methods are ignored.
By setting my app as a Console Application, all attempts to display Windows
Forms are ignored.

Is there any way to get a single application to act in both of these
different ways?

Thanks,
 
J

jan.hancic

You can show windows form even dough your proejct is console type. You
just have to refrence the Windows.Forms.dll.

I would suggsest you that you put your logic and everything that does
not need a interface in a DLL and then make 3 seperate applications.
One for starting either a console or windows version. And then one
consoel and one windows version.
 
O

Oenone

You can show windows form even dough your proejct is console type. You
just have to refrence the Windows.Forms.dll.

You're right -- and I described the behaviour incorrectly in my original
post. This way it works fine except that when running from within Windows,
an empty console window appears in the background, which looks awful.
I would suggsest you that you put your logic and everything that does
not need a interface in a DLL and then make 3 seperate applications.
One for starting either a console or windows version. And then one
consoel and one windows version.

Thanks for the suggestion!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top