Show / Hide the console in an application in C #

2

I searched on how to show / hide the console in an application in C # in the forums in Portuguese and did not find it. Looking for internationals I came across several solutions but found a very easy application and would like to share with others.

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

    
asked by anonymous 20.03.2017 / 20:51

1 answer

2

Follow 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);
    
20.03.2017 / 20:53