Windows-8.1

How to Hide and Show the Console Window Associated with your own C# app?

Here’s how:

Add a reference to InteropServices in your class.

using System.Runtime.InteropServices;

Next, define two function signatures GetConsoleWindow and ShowWindow. These functions use kernel32.dll and user32.dll respectively.

[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();

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

const int SW_HIDE = 0;
const int SW_SHOW = 5;

Finally, use these functions as follows. Get the handle by calling the GetConsoleWindow function.

var handle = GetConsoleWindow();

To hide a Window:

// Hide
ShowWindow(handle, SW_HIDE);

To show a Window:

// Show
ShowWindow(handle, SW_SHOW);

Vivek Maskara

I am pursuing BTech in Software Engineering from Delhi Technological University. I develop apps, create websites and blog about my app experiences.

Read more:
How to create your first Windows Phone app
How to change the App name and Tile name of your Windows phone app
Data binding in Windows Phone app – One way binding
Close