Does not contain a static 'main' method suitable for an entry point

前端 未结 26 1764
时光说笑
时光说笑 2020-12-05 12:55

I began organizing my code to day into seperarate .cs files, and in order to allow the methods that work with the UI to continue to do so I would create the .cs code under t

26条回答
  •  感动是毒
    2020-12-05 13:13

    For future readers who faced same issue with Windows Forms Application, one solution is to add these lines to your main/start up form class:

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

    Then go to project properties > Application > Startup Object dropdown, should see the namespace.MyMainForm, select it, clean and build the solution. And it should work.

提交回复
热议问题