在kernel32.dll导入控制台的两个方法:AllocConsole()+FreeConsole()
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[DllImport("kernel32.dll")]
static extern bool FreeConsole();
[DllImport("kernel32.dll")]
public static extern bool AllocConsole();
[STAThread]
static void Main()
{
AllocConsole();//调用系统API,调用控制台窗口
Console.WriteLine("Hello World");
Console.ReadKey();
FreeConsole();//释放控制台
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
SqlServerString.SqlConnectString = "LTKDB";
Application.Run(new Form1());
}
}