본문 바로가기

프로그램 경험/.Net

[C#] 콘솔창에 색상 넣기

[DllImport("kernel32.dll", EntryPoint="SetConsoleTextAttribute")]
private static extern bool SetConsoleTextAttribute(IntPtr h_ConsoleOutput, Int16 u16_Attributes);

[DllImport("kernel32.dll", EntryPoint="GetStdHandle")]
private static extern IntPtr GetStdHandle(int u32_Device);

const int GREY   = 0x7;
const int WHITE  = 0xF;
const int GREEN  = 0xA;
const int CYAN   = 0xB;
const int RED    = 0xC;
const int YELLOW = 0xE;

const int STD_OUTPUT_HANDLE = -11;
Int16 u16_Color = YELLOW;
string s_Text = "Hello Console~";

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), u16_Color); 
Console.WriteLine(s_Text);


티스토리 툴바