How do I convert a .NET console application to a Winforms or WPF application

后端 未结 2 1822
余生分开走
余生分开走 2020-11-30 05:19

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 ex

相关标签:
2条回答
  • 2020-11-30 05:58

    For completeness - and for other newbs like me - you also need to add:

    using System.Windows.Forms;

    ... to the top of Program.cs

    0 讨论(0)
  • 2020-11-30 06:13

    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

    enter image description here

    0 讨论(0)
提交回复
热议问题