I frequently start with a simple console application to try out an idea, then create a new GUI based project and copy the code in. Is there a better way? Can I convert my existing console application easily?
Asked
Active
Viewed 3.8k times
2 Answers
82
Just add a new Winform, add the following code to your Main
:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Also, be sure the [STAThread]
attribute is declared above your Main
function to indicate the COM threading model your Windows application will use (more about STAThread here).
Then right click your project and select properties and change the "Output type" to Windows application and you're done.
EDIT :
In VS2008 the property to change is Application type
-
If your app is using the Compact Framework then you only need to add `Application.Run(new Form1());`. The first two lines are not valid. – DeanOC May 09 '13 at 20:28
-
7Don't forget to add `[STAThreadAttribute]` to your `Main` method definition. – Slight Aug 06 '15 at 21:36
30
For completeness - and for other newbs like me - you also need to add:
using System.Windows.Forms;
... to the top of Program.cs

dbruning
- 5,042
- 5
- 34
- 35