Skip to content

Instantly share code, notes, and snippets.

@seayxu
Last active January 4, 2018 01:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seayxu/7581885ea80597f71786 to your computer and use it in GitHub Desktop.
Save seayxu/7581885ea80597f71786 to your computer and use it in GitHub Desktop.
Show console in csharp winform func
namespace Demo
{
static class Program
{
[DllImport("kernel32.dll")]
static extern bool FreeConsole();//Call Sysytem API,Disposed Console
[DllImport("kernel32.dll")]
public static extern bool AllocConsole();//Call Sysytem API,Show Console
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
AllocConsole();//Show Console
Application.Run(new Form1());
FreeConsole();//Disposed Console
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment