Skip to content

Instantly share code, notes, and snippets.

@EtherZa
Created July 7, 2017 14:25
Show Gist options
  • Save EtherZa/742c43b4c176fa893b5c6a7273e63250 to your computer and use it in GitHub Desktop.
Save EtherZa/742c43b4c176fa893b5c6a7273e63250 to your computer and use it in GitHub Desktop.
Output to console in Windows Forms application
namespace ShowConsole
{
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public static class Program
{
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AllocConsole();
[STAThread]
public static void Main()
{
Program.AllocConsole();
Console.WriteLine("Hello world");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment