美文网首页
在Form应用程序中引入控制台

在Form应用程序中引入控制台

作者: 向着远方奔跑 | 来源:发表于2019-03-22 11:40 被阅读0次

    在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());
            }
        }
    

    相关文章

      网友评论

          本文标题:在Form应用程序中引入控制台

          本文链接:https://www.haomeiwen.com/subject/kxjlvqtx.html