Show / Hide console in an application in c#

Asked

Viewed 528 times

2

I looked for how to show/hide the console in a c# application in the English forums and could not find it. Looking at international I came across several solutions but I found one very easy to apply and I would like to share with others.

How to hide (and show) the console window associated with your own console application?

1 answer

2


Follows the code:

using System.Runtime.InteropServices;
[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;
var handle = GetConsoleWindow();

// Ocultar
ShowWindow(handle, SW_HIDE);

// Mostrar
ShowWindow(handle, SW_SHOW);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.