Show/Hide the console window of a C# console application

前端 未结 8 2280
走了就别回头了
走了就别回头了 2020-11-22 10:13

I googled around for information on how to hide one’s own console window. Amazingly, the only solutions I could find were hacky solutions that involved FindWindow()

8条回答
  •  星月不相逢
    2020-11-22 11:03

    If you don't want to depends on window title use this :

        [DllImport("user32.dll")]
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
    

    ...

        IntPtr h = Process.GetCurrentProcess().MainWindowHandle;
        ShowWindow(h, 0);
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new FormPrincipale());
    

提交回复
热议问题