C#在winform中调用系统控制台输出
生活随笔
收集整理的這篇文章主要介紹了
C#在winform中调用系统控制台输出
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?SeayXu 原文C#在winform中調(diào)用系統(tǒng)控制臺輸出
在Winform程序中有時(shí)候調(diào)試會(huì)通過Console.Write()方式輸出一些信息,這些信息是在Visual Studio的輸出窗口顯示。
所以就會(huì)想,能不能調(diào)用系統(tǒng)的Cmd窗口輸出呢,經(jīng)過一番查閱,發(fā)現(xiàn)是可以的,現(xiàn)在就把方法寫下了:
主要用到的是win32 API函數(shù)實(shí)現(xiàn)的:
[DllImport("kernel32.dll")] static extern bool FreeConsole(); [DllImport("kernel32.dll")] public static extern bool AllocConsole();在Program.cs文件中調(diào)用方法即可
完整代碼:
using System; using System.Collections.Generic; using System.Windows.Forms; using System.Runtime.InteropServices;namespace XY.WinformDebug { static class Program {[DllImport("kernel32.dll")]static extern bool FreeConsole();[DllImport("kernel32.dll")]public static extern bool AllocConsole();/// <summary>/// 應(yīng)用程序的主入口點(diǎn)。/// </summary> [STAThread]static void Main(){AllocConsole();//調(diào)用系統(tǒng)API,調(diào)用控制臺窗口 Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new FrmMain());FreeConsole();//釋放控制臺 }} }?
轉(zhuǎn)載于:https://www.cnblogs.com/arxive/p/6043197.html
總結(jié)
以上是生活随笔為你收集整理的C#在winform中调用系统控制台输出的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【drp 12】再识转发和重定向:Spr
- 下一篇: c# char unsigned_dll