C# 在 WinForm程序中打开命令行(附:Visual Studio 命令行不显示解决办法)

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Threading.Tasks;
 5 using System.Windows.Forms;
 6 using System.Runtime.InteropServices; // 加命名空间 : DllImport
 7 
 8 namespace Backend_Logic.socket_learning
 9 {
10     static class ServerProgram
11     {
12 
13         //  引用win32api
14         [DllImport("kernel32.dll")]
15         static extern bool FreeConsole();
16         [DllImport("kernel32.dll")]
17         public static extern bool AllocConsole();
18 
19         /// <summary>
20         /// 应用程序的主入口点。
21         /// </summary>
22         [STAThread]
23         static void Main()
24         {
25 #if DEBUG
26             AllocConsole();//调用系统API,调用控制台窗口
27             //Console.Read();
28             Console.WriteLine("启动程序");
29 #endif
30             Application.EnableVisualStyles();
31             Application.SetCompatibleTextRenderingDefault(false);
32             Application.Run(new ServerForm());
33 #if DEBUG
34             FreeConsole();
35 #endif
36         }
37     }
38 }

 

posted @ 2020-12-17 16:01  潘工  阅读(753)  评论(0编辑  收藏  举报