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 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步