![](/img/trans.png)
[英]How do I stop the C# compiler output from wrapping in the Visual Studio 2015 output window?
[英]How do I write color text to the Visual Studio output window from c#?
我想從 c# 將彩色文本寫入 Visual Studio 輸出窗口。 我想從我的單元測試中輸出紅色代碼。
我在試圖弄清楚為什么我的 Visual Studio 2017 輸出窗口中的某些文本行是紅色時發現了這個問題,以及我如何完成同樣的事情。
我發現我可以通過寫出一行來獲得紅色文本,其中包括:
Error:
”的實例(錯誤,冒號,后跟一個空格)Error:
”的另一個實例(錯誤,冒號,后跟一個空格)Error *
”的 1 個實例(錯誤,后跟一個空格,然后是其他一些字符)一個例子:
Debug.WriteLine("Error: This line will be red Error: Error Jeff");
實際上有擴展。 我為 Visual Studio 2010 使用 VSCommands的精簡版(免費)版本。 使用 Pro 版本,可以設置正則表達式來進行着色。 在精簡版中,我在調試消息中添加了“警告”文本,它以淺棕色書寫。
我想從c#將彩色文本寫入Visual Studio輸出窗口。 我想從單元測試中輸出紅色代碼。
據我所知,Visual Studio 中的輸出窗口是一個“簡單文本框”類型的控件,不支持彩色文本。
編輯下面的代碼用於在 Windows 控制台中顯示輸出,而不是在 Visual Studio 輸出窗口中顯示(感謝 @AnthonyLambert 糾正我)。
Console.ForegroundColor = ConsoleColor.Magenta; //Choose from the Enum
Console.WriteLine("This message is to be in Magenta!");
Console.ResetColor();//Reset to default
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.