在kernel32.dll導(dǎo)入控制臺(tái)的兩個(gè)方法:AllocConsole()+FreeConsole()
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
static class Program
{
/// <summary>
/// 應(yīng)用程序的主入口點(diǎn)。
/// </summary>
[DllImport("kernel32.dll")]
static extern bool FreeConsole();
[DllImport("kernel32.dll")]
public static extern bool AllocConsole();
[STAThread]
static void Main()
{
AllocConsole();//調(diào)用系統(tǒng)API,調(diào)用控制臺(tái)窗口
Console.WriteLine("Hello World");
Console.ReadKey();
FreeConsole();//釋放控制臺(tái)
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
SqlServerString.SqlConnectString = "LTKDB";
Application.Run(new Form1());
}
}