Converting Color to ConsoleColor?

前端 未结 8 1346
面向向阳花
面向向阳花 2020-12-02 21:22

What is the best way to convert a System.Drawing.Color to a similar System.ConsoleColor?

8条回答
  •  再見小時候
    2020-12-02 21:48

    The distinct default "white-on-blue" color of PowerShell.exe before version 6 (and any ConsoleWindowClass window) is actually DarkYellow on DarkMagenta if you check $Host.UI.RawUI. This is because the ConsoleColor enum values are just indices into the console color table, which is configurable (see this answer about DarkYellow).

    Here are the hex RGB values for the default console color table:

    Value Hex RGB Name
        0 #000000 Black
        1 #000080 DarkBlue
        2 #008000 DarkGreen
        3 #008080 DarkCyan
        4 #800000 DarkRed
        5 #012456 DarkMagenta
        6 #EEEDF0 DarkYellow
        7 #C0C0C0 Gray
        8 #808080 DarkGray
        9 #0000FF Blue
       10 #00FF00 Green
       11 #00FFFF Cyan
       12 #FF0000 Red
       13 #FF00FF Magenta
       14 #FFFF00 Yellow
       15 #FFFFFF White
    

提交回复
热议问题