public class color
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool SetConsoleTextAttribute(
IntPtr hConsoleOutput,
CharacterAttributes wAttributes); /* declaring the setconsoletextattribute function*/
[DllImport("kernel32.dll")]
public static extern IntPtr GetStdHandle(int nStdHandle);
public enum CharacterAttributes
{
aa = 0x0007,
FOREGROUND_BLUE = 0x0001,
FOREGROUND_GREEN = 0x0002,
ground_green = 0x0002,
FOREGROUND_RED = 0x0004,
FOREGROUND_INTENSITY = 0x0008,
BACKGROUND_BLUE = 0x0010,
BACKGROUND_GREEN = 0x0020,
BACKGROUND_RED = 0x0040,
BACKGROUND_INTENSITY = 0x0080,
COMMON_LVB_LEADING_BYTE = 0x0100,
COMMON_LVB_TRAILING_BYTE = 0x0200,
COMMON_LVB_GRID_HORIZONTAL = 0x0400,
COMMON_LVB_GRID_LVERTICAL = 0x0800,
COMMON_LVB_GRID_RVERTICAL = 0x1000,
COMMON_LVB_REVERSE_VIDEO = 0x4000,
COMMON_LVB_UNDERSCORE = 0x8000
}
}
调用:
声明: IntPtr hOut = color.GetStdHandle(-11);
输出时:color. SetConsoleTextAttribute(hOut,color. CharacterAttributes.FOREGROUND_INTENSITY);