How to make the C # application window invisible and not show in the tray?

  • You can make a console application and then change the Output Type to Windows Application and the application will be windowless. - vitidev

1 answer 1

For example, in WPF, you can use Window.Hide() ( Show() to cancel). Or Window.Visibility = Visibility.Collapsed ( Visibility.Visible for cancellation). Or if you don’t want to show a window at all, remove StartupUri in App.xaml (and change ShutdownMode , of course).


In WinForms, Form.Visible = false; Form.ShowInTaskbar = false; helps Form.Visible = false; Form.ShowInTaskbar = false; Form.Visible = false; Form.ShowInTaskbar = false; . To not show the window from the beginning, use Application.Run() without a form. Or do not run Application at all if you do not need to show the window later.


Console applications run in the console, so if you need this effect, it is better to write a non-console application. If you really need, you can use P / Invoke (borrowed from here ):

 using System.Runtime.InteropServices; static class NativeMethods { [DllImport("kernel32.dll")] static public extern IntPtr GetConsoleWindow(); [DllImport("user32.dll")] static public extern bool ShowWindow(IntPtr hWnd, int nCmdShow); public const int SW_HIDE = 0; public const int SW_SHOW = 5; } var handle = NativeMethods.GetConsoleWindow(); NativeMethods.ShowWindow(handle, NativeMethods.SW_HIDE); // убрать NativeMethods.ShowWindow(handle, NativeMethods.SW_SHOW); // вернуть назад 

But at the same time, the window will still appear first, and only then it will disappear. (And if you launch another console application in your console, then you will hide its console, which is even worse, to be honest.) Therefore, I would not recommend to go this way.


If you have already created a console project, you can easily turn it into a windows application by changing the project properties (Application tab) Output type from Console Application to Windows Application.

  • and if the console application? - Rakzin Roman
  • @RakzinRoman: Console application runs in console. If you need to avoid it, do not create a console application, create a window application. - VladD 4:16 pm
  • Not important - winforms / wpf / console - you just need to do so that the window is not displayed - Rakzin Roman
  • @RakzinRoman: Then create a window application, but do not give a command to display the window. - VladD
  • using System.Diagnostics; using System.Threading; namespace ConsoleApplication1 {class Program {static void Main (string [] args) {Thread.Sleep (2000); System.Diagnostics.Process.Start ("setup.exe"); }}} - Rakzin Roman