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

前端 未结 8 2127
走了就别回头了
走了就别回头了 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:04

    If you don't have a problem integrating a small batch application, there is this program called Cmdow.exe that will allow you to hide console windows based on console title.

    Console.Title = "MyConsole";
    System.Diagnostics.Process HideConsole = new System.Diagnostics.Process();
    HideConsole.StartInfo.UseShellExecute = false;
    HideConsole.StartInfo.Arguments = "MyConsole /hid";
    HideConsole.StartInfo.FileName = "cmdow.exe";
    HideConsole.Start();
    

    Add the exe to the solution, set the build action to "Content", set Copy to Output Directory to what suits you, and cmdow will hide the console window when it is ran.

    To make the console visible again, you just change the Arguments

    HideConsole.StartInfo.Arguments = "MyConsole /Vis";
    
    0 讨论(0)
  • 2020-11-22 11:05

    Why do you need a console application if you want to hide console itself? =)

    I recommend setting Project Output type to Windows Application instead of Console application. It will not show you console window, but execute all actions, like Console application do.

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