using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; //1加命名空间 namespace WindowsFormsApp1 { static class Program { // 引用win32api [DllImport("kernel32.dll")] static extern bool FreeConsole(); [DllImport("kernel32.dll")] public static extern bool AllocConsole(); /// <summary> /// 应用程序的主入口点。 /// </summary> /// [STAThread] static void Main() { AllocConsole();//调用系统API,调用控制台窗口 Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form1.Fun(); Console.ReadLine(); Application.Run(new Form1()); FreeConsole();//释放控制台 } } }