How to change a C # console project to a Windows forms application project?

A C # console project has been created that contains the console class (program.cs). I added a form (Main.cs) to the project.

I want to do one of the following things with my project
 1. Change the project to a Windows Form application , can I change it to a Windows Form application without creating a new project. 2. Set the Main class as the launch object . Check the "Application" tab in the properties window. The main class is not included in the list of Startup objects.

+3
source share
4 answers

What you should do:

  • Project + Properties, Application, " Windows"
  • Project + , System.Windows.Forms System.Drawing
  • Main() Program.cs. [STAThread].
  • Main(), :

    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new YourMainForm());
    }
    

"YourMainForm" . Main() - , , , . Run(), , .

+6

Console Application Windows Application.

+3
  • Windows Form → "" → " " " Windows".

  • Set the Main class as a launch object You do not need to install the launch object if you have only one class containing the static Main () method. To start a Windows application, you need to implement the Main method containing the call Application.Run(). You can create a Windows forms project using the new project wizard to see an example.

+2
source

alt text

+1
source

Source: https://habr.com/ru/post/1772686/


All Articles