Behavior in WinForm/Console Hybrid Application

后端 未结 4 2031
走了就别回头了
走了就别回头了 2021-01-20 14:28

I have a WinForm project that I want to be usable as a console app if certain arguments are passed into it. Using some tips I read from here, I used the following code to m

4条回答
  •  一整个雨季
    2021-01-20 15:00

    Maybe I've been doing it wrong but I've always done hybrids like this:

    [STAThread]
    public static int Main(string[] args)
    {
       if (args.Length > 0)
       {
          // run console code here
       }
       else
       {
          // start up the win form app
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
          Application.Run(new MainForm());
       }
    
       return 0;
    }
    

提交回复
热议问题