开发者

redefining Console colour palette in c#

开发者 https://www.devze.com 2023-01-06 12:38 出处:网络
Could somebody please tell me how can I redefine the colour palette 开发者_如何学Pythonof the Console in C#?Yeah, it\'s possible.You\'ll need a bunch of P/Invoke declarations to use code like this:

Could somebody please tell me how can I redefine the colour palette 开发者_如何学Pythonof the Console in C#?


Yeah, it's possible. You'll need a bunch of P/Invoke declarations to use code like this:

CONSOLE_SCREEN_BUFFER_INFOEX info;
info.cbSize = sizeof(info);
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfoEx(hConsole, &info);
info.ColorTable[14] = RGB(255, 128, 0);  // Replace yellow
SetConsoleScreenBufferInfoEx(hConsole, &info);
SetConsoleTextAttribute(hConsole, FOREGROUNDINTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);

Visit pinvoke.net or use the P/Invoke Interop Assistant to get the declarations you need to use this code.

0

精彩评论

暂无评论...
验证码 换一张
取 消