redefining Console colour palette in c#

后端 未结 1 989
攒了一身酷
攒了一身酷 2020-12-21 07:49

Could somebody please tell me how can I redefine the colour palette of the Console in C#?

相关标签:
1条回答
  • 2020-12-21 08:34

    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 讨论(0)
提交回复
热议问题