1. 程式人生 > 實用技巧 >C# 在 WinForm程式中開啟命令列(附:Visual Studio 命令列不顯示解決辦法)

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 }