private static extern bool SetConsoleScreenBufferInfoEx( IntPtr hConsoleOutput, ref ConsoleScreenBufferInfoEx csbe);
private void UpdateConsoleColorPalette() { var palette = Graphics.Palette; if (palette == null || lastPalette == palette) { return; } var info = new ConsoleScreenBufferInfoEx(); info.cbSize = Marshal.SizeOf(info); if (!GetConsoleScreenBufferInfoEx(consoleHandle, ref info)) { throw new Exception(); } for (var i = 0; i < palette.Entries.Length; i++) { switch (i) { case 0: info.black = Ref(palette.Entries[i]); break; case 1: info.darkBlue = Ref(palette.Entries[i]); break; case 2: info.darkGreen = Ref(palette.Entries[i]); break; case 3: info.darkCyan = Ref(palette.Entries[i]); break; case 4: info.darkRed = Ref(palette.Entries[i]); break; case 5: info.darkMagenta = Ref(palette.Entries[i]); break; case 6: info.darkYellow = Ref(palette.Entries[i]); break; case 7: info.gray = Ref(palette.Entries[i]); break; case 8: info.darkGray = Ref(palette.Entries[i]); break; case 9: info.blue = Ref(palette.Entries[i]); break; case 10: info.green = Ref(palette.Entries[i]); break; case 11: info.cyan = Ref(palette.Entries[i]); break; case 12: info.red = Ref(palette.Entries[i]); break; case 13: info.magenta = Ref(palette.Entries[i]); break; case 14: info.yellow = Ref(palette.Entries[i]); break; case 15: info.white = Ref(palette.Entries[i]); break; } } info.srWindow.Bottom++; info.srWindow.Right++; if (!SetConsoleScreenBufferInfoEx(consoleHandle, ref info)) { throw new Exception(); } lastPalette = Graphics.Palette; }