How to hide the Console Application in C#

How to hide the console application in C#

Step 1Click New Project, then select Visual C# on the left, then Windows and then select Console Application. Name your project "HideConsole" and then click OK

hide console application in c#Step 2: Add code to Program class as below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

namespace HideConsole
    class Program
        private static extern IntPtr GetConsoleWindow();
        private static extern bool ShowWindow(IntPtr hWnd, int cmdShow);

        static void Main(string[] args)
            Console.WriteLine("Press any key to hide me.");
            IntPtr hWnd = GetConsoleWindow();
            if (hWnd != IntPtr.Zero)
                ShowWindow(hWnd, 0);//hide
                ShowWindow(hWnd, 1);//show



Related Posts