Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I have a program that is nearly completed and written as a C# Console application. I do this because this program works with directories a lot and I am most comfortable writing console applications.

What I need is a way to have a popup form launched from my console application. The form doesnt need to do anything other than display some graphics generated by the console app.

I have looked at other people handel this problem by converting their entire project to a windows form application. I really dont want to do this as all i need a form for is a popup window with a graph displayed on it.

Is this even possible? And can someone either explain how to get this started or point me in the direction of an article that explains this.

Thank You,
Mike.
Posted

Nothing will work unless you eventually run System.Windows.Forms.Application.Run [EDIT] or, alternatively, System.Windows.Forms.Form.ShowDialog [END EDIT].

This is where the main cycle of a Forms application is executed; and this is something which I would call Forms application anyway. No need to argue over terminology; what I just told you the essence of thing.

Let me tell you that your "I don't want" needs some motivation which you did not provide. There is nothing wrong with Forms application; and you can keep your console code if you want, so from any practical point of view, you won't have any problem.

Now, don't be confused by the term "Console Application" as the application type. It is not alternative to "Windows Application". Simply put, "Windows Application" simply says: "hide the console", nothing else. If does not even have to have a Window or a Form (!). That said, make it a "Console Application", but with the forms. One practical way of doing it is this: 1) create a new Forms application; 2) change application type to "Console Application"; try it: it will run as a Forms application but will show a console; 3) move you console code to the application.

After your do it, you can modify your entry point method (which is usually "Main") to start with Console code, run System.Windows.Forms.Application.Run(Form) with you form later or on some condition, or whatever you like.

This way, you have a mixture of Console and Forms application, and no problems.

—SA
 
Share this answer
 
v3
Comments
Tarakeshwar Reddy 19-Jan-12 18:09pm    
*bows* As usual sir you have proved why are you the best in answering questions. I got to learn a lot from you.
Sergey Alexandrovich Kryukov 19-Jan-12 18:42pm    
Thank you very much, Tarakeshwar.
--SA
Orcun Iyigun 19-Jan-12 19:05pm    
Respect :) I totally agree with you.
Sergey Alexandrovich Kryukov 19-Jan-12 21:00pm    
Thank you, Orcun.
--SA
Abey Thomas 19-Jan-12 20:34pm    
Great answer!
You would need to reference the System.Windows.Forms.dll and you can create a Form object and add the necessary controls to it.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 19-Jan-12 17:21pm    
Incomplete -- can only confuse OP at the attempt to implement it. Please see my answer.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900