public static void Plot() { SafeFileHandle h = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero); CONSOLE_FONT_INFO_EX ConsoleFontInfo = new CONSOLE_FONT_INFO_EX(); ConsoleFontInfo.cbSize = (uint)Marshal.SizeOf(ConsoleFontInfo); ConsoleFontInfo.FaceName = "Lucida Console"; ConsoleFontInfo.dwFontSize.X = 4; ConsoleFontInfo.dwFontSize.Y = 7; SetCurrentConsoleFontEx(GetStdHandle(StdHandle.OutputHandle), false, ref ConsoleFontInfo); if (!h.IsInvalid) { bool b = WriteConsoleOutput(h, buf, new Coord() { X = 230, Y = 135 }, new Coord() { X = 0, Y = 0 }, ref rect); } }
private unsafe void SetFont(short size) { const string fontName = "MS Gothic"; var hnd = GetStdHandle(STD_OUTPUT_HANDLE); if (hnd == INVALID_HANDLE_VALUE) { return; } var info = new CONSOLE_FONT_INFO_EX(); info.cbSize = (uint)Marshal.SizeOf(info); if (!GetCurrentConsoleFontEx(hnd, false, ref info)) { return; } var newInfo = new CONSOLE_FONT_INFO_EX(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = TMPF_TRUETYPE; var ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); newInfo.dwFontSize = new Coord(size, size); newInfo.FontWeight = info.FontWeight; SetCurrentConsoleFontEx(hnd, false, newInfo); }
static unsafe void Main(string[] args) { string fontName = "Lucida Console"; IntPtr hnd = GetStdHandle(STD_OUTPUT_HANDLE); if (hnd != INVALID_HANDLE_VALUE) { CONSOLE_FONT_INFO_EX info = new CONSOLE_FONT_INFO_EX(); info.cbSize = (uint)Marshal.SizeOf(info); // Set console font to Lucida Console. CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = TMPF_TRUETYPE; IntPtr ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); // Get some settings from current font. newInfo.dwFontSize = new COORD(info.dwFontSize.X, info.dwFontSize.Y); newInfo.FontWeight = info.FontWeight; SetCurrentConsoleFontEx(hnd, false, newInfo); } string strName; do { Console.WriteLine("Please enter your name to have a more descriptive greeting than the greeting that Mr. Letts's program provides (Enter \"" + EXIT_KEYWORD + "\" without the quotation marks to exit out of the program):"); strName = Console.ReadLine(); Console.WriteLine(GenerateMoreDescriptiveGreeting(strName)); } while (strName != EXIT_KEYWORD); Console.WriteLine("See you later, random person!"); Console.ReadKey(); }
/// <summary> /// General setting for all game /// </summary> private static void GeneralSetting() { //set title Console.Title = Constants.TitleOfApp; //set encoding Console.OutputEncoding = Encoding.UTF8; Console.InputEncoding = Encoding.Unicode; //set background color Console.BackgroundColor = Constants.BackgroundColor; Console.ForegroundColor = Constants.MainColor; #region work with font //get info aboute font IntPtr handle = GetStdHandle(STD_OUTPUT_HANDLE); var fontInfo = new CONSOLE_FONT_INFO_EX(); //setting info aboute font fontInfo.FaceName = Constants.MainConsoleFont; fontInfo.dwFontSize.X = 20; fontInfo.dwFontSize.Y = 20; //save change of font SetCurrentConsoleFontEx(handle, false, fontInfo); //set console size Console.SetWindowSize(31, 26); Console.SetBufferSize(31, 26); #endregion //set cursor size Console.CursorSize = Constants.CurrentCursorSize; }
public static void SetConsoleFont(string fontName = "Lucida Console") { unsafe { IntPtr hnd = GetStdHandle(STD_OUTPUT_HANDLE); if (hnd != INVALID_HANDLE_VALUE) { CONSOLE_FONT_INFO_EX info = new CONSOLE_FONT_INFO_EX(); // Info regarding the current font info.cbSize = (uint)Marshal.SizeOf(info); // Size of the info structure // Set console font to Lucida Console. CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = TMPF_TRUETYPE; IntPtr ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); // All previous information regarding the previous font are at info // Setting new font using newInfo................................. newInfo.dwFontSize = new COORD(FONT_SIZE_X, FONT_SIZE_X); newInfo.FontWeight = FONT_WEIGHT; SetCurrentConsoleFontEx(hnd, false, ref newInfo); } } }
public static unsafe void ChangeFont() { string fontName = "MS Gothic"; IntPtr hnd = GetStdHandle(STD_OUTPUT_HANDLE); if (hnd != INVALID_HANDLE_VALUE) { CONSOLE_FONT_INFO_EX info = new CONSOLE_FONT_INFO_EX(); info.cbSize = (uint)Marshal.SizeOf(info); bool tt = false; // First determine whether there's already a TrueType font. if (GetCurrentConsoleFontEx(hnd, false, ref info)) { tt = (info.FontFamily & TMPF_TRUETYPE) == TMPF_TRUETYPE; if (tt) { return; } CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = TMPF_TRUETYPE; IntPtr ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); // Get some settings from current font. newInfo.dwFontSize = new COORD(info.dwFontSize.X, info.dwFontSize.Y); newInfo.FontWeight = info.FontWeight; SetCurrentConsoleFontEx(hnd, false, newInfo); } } }
public static void SetConsoleFont(string fontName, short size) { unsafe { IntPtr hnd = GetStdHandle(STD_OUTPUT_HANDLE); if (hnd != INVALID_HANDLE_VALUE) { CONSOLE_FONT_INFO_EX info = new CONSOLE_FONT_INFO_EX(); info.cbSize = (uint)Marshal.SizeOf(info); // Set console font to Lucida Console. CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = TMPF_TRUETYPE; IntPtr ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); info.dwFontSize.X = (short)size; info.dwFontSize.Y = (short)size; // Get some settings from current font. newInfo.dwFontSize = new COORD(info.dwFontSize.X, info.dwFontSize.Y); newInfo.FontWeight = info.FontWeight; SetCurrentConsoleFontEx(hnd, false, ref newInfo); } } }
public static bool SetFont(string fontName = "Lucida Console") { unsafe { IntPtr hnd = GetStdHandle(STD_OUTPUT_HANDLE); if (hnd != INVALID_HANDLE_VALUE) { CONSOLE_FONT_INFO_EX info = new CONSOLE_FONT_INFO_EX(); info.cbSize = (uint)Marshal.SizeOf(info); CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = TMPF_TRUETYPE; IntPtr ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); newInfo.dwFontSize = new COORD(info.dwFontSize.X, info.dwFontSize.Y); newInfo.FontWeight = info.FontWeight; return(SetCurrentConsoleFontEx(hnd, false, ref newInfo)); } return(false); } }
public static void SetConsoleFont(short fontHeight, string fontName = "Consolas") { unsafe { IntPtr hnd = GetStdHandle(StdHandle.OutputHandle); if (hnd != INVALID_HANDLE_VALUE) { // Set console font to Lucida Console. CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = 32; newInfo.nFont = 0; IntPtr ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); CurrentFontSize = new COORD((short)(fontHeight / 2), fontHeight); // Get some settings from current font. newInfo.dwFontSize = CurrentFontSize; newInfo.FontWeight = 400; SetCurrentConsoleFontEx(hnd, false, ref newInfo); } } AdjustBuffer(); }
static void SetConsoleFont(IntPtr hnd, string fontName) { if (hnd != INVALID_HANDLE_VALUE && !string.IsNullOrEmpty(fontName)) { CONSOLE_FONT_INFO_EX info = new CONSOLE_FONT_INFO_EX(); info.cbSize = (uint)Marshal.SizeOf(info); bool tt = false; if (GetCurrentConsoleFontEx(hnd, false, ref info)) { tt = (info.FontFamily & TMPF_TRUETYPE) == TMPF_TRUETYPE; if (tt) { Console.WriteLine("The console already is using a TrueType font."); //return; } CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = TMPF_TRUETYPE; newInfo.FaceName = fontName; // Get some settings from current font. newInfo.dwFontSize = new COORD(info.dwFontSize.X, info.dwFontSize.Y); newInfo.FontWeight = info.FontWeight; SetCurrentConsoleFontEx(hnd, false, ref newInfo); } } }
private static CONSOLE_FONT_INFO_EX GetCurrentFontInfo(IntPtr handle) { var info = new CONSOLE_FONT_INFO_EX(); info.cbSize = (uint)Marshal.SizeOf(info); GetCurrentConsoleFontEx(handle, false, ref info); return(info); }
public static unsafe void Main(string[] args) { //string fontName = "Lucida Console"; string fontName = "Anonymous Pro"; IntPtr hnd = GetStdHandle(STD_OUTPUT_HANDLE); if (hnd != INVALID_HANDLE_VALUE) { CONSOLE_FONT_INFO_EX info = new CONSOLE_FONT_INFO_EX(); info.cbSize = (uint)Marshal.SizeOf(info); bool tt = false; // First determine whether there's already a TrueType font. if (GetCurrentConsoleFontEx(hnd, false, ref info)) { tt = (info.FontFamily & TMPF_TRUETYPE) == TMPF_TRUETYPE; if (tt) { Debug.WriteLine("The console already is using a TrueType font."); //return; } // Set console font to Lucida Console. CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = TMPF_TRUETYPE; IntPtr ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); // Get some settings from current font. newInfo.dwFontSize = new COORD(info.dwFontSize.X, info.dwFontSize.Y); newInfo.FontWeight = info.FontWeight; SetCurrentConsoleFontEx(hnd, false, newInfo); } } if (args.Length >= 1) { ed = new Editor(args[0]); } else { ed = new Editor(); } using (Program prg = new Program()) { try { prg.Run(); } finally { //Curses.EndWin(); } } }
internal static bool IsUsingRasterFont() { var handle = _outputHandle.Value.DangerousGetHandle(); var fontInfo = new CONSOLE_FONT_INFO_EX { cbSize = Marshal.SizeOf(typeof(CONSOLE_FONT_INFO_EX)) }; bool result = GetCurrentConsoleFontEx(handle, false, ref fontInfo); // From https://docs.microsoft.com/windows/win32/api/wingdi/ns-wingdi-textmetrica // tmPitchAndFamily - A monospace bitmap font has all of these low-order bits clear; return(result && (fontInfo.FontFamily & FontFamily.LOWORDER_BITS) == 0); }
private static CONSOLE_FONT_INFO_EX GetCurrentFontEx(IntPtr hConsole) { if (hConsole.IsInvalidHandle()) { return(null); } //Obtain the current console font index CONSOLE_FONT_INFO_EX fontInfo = new CONSOLE_FONT_INFO_EX(); return(!Win32.GetCurrentConsoleFontEx(hConsole, false, fontInfo) ? null : fontInfo); }
internal static bool IsUsingRasterFont() { CONSOLE_FONT_INFO_EX fontInfo = new CONSOLE_FONT_INFO_EX(); fontInfo.cbSize = Marshal.SizeOf(fontInfo); var handle = _outputHandle.Value.DangerousGetHandle(); bool result = GetCurrentConsoleFontEx(handle, false, ref fontInfo); // If this bit is set the font is a variable pitch font. // If this bit is clear the font is a fixed pitch font. // Note very carefully that those meanings are the opposite of what the constant name implies. return(!fontInfo.FontFamily.HasFlag(FontFamily.TMPF_FIXED_PITCH)); }
public static bool SetCurrentFontEx([NotNull] string fontName = FONT_DEF, FontMask fontFamily = FontMask.TRUETYPE_FONTTYPE, short size = 11, FontWeight weight = FontWeight.FW_DONTCARE) { CONSOLE_FONT_INFO_EX fontInfoEx = new CONSOLE_FONT_INFO_EX { lpszFaceName = fontName, nFamily = fontFamily, nWidth = size, nHeight = size, nWeight = weight }; return(SetCurrentFontEx(fontInfoEx)); }
public static void SetCurrentFont(string fontName, short?xSize = null, short?ySize = null, int?weight = null) { var handle = GetStdHandle(StdHandle.OutputHandle); var info = GetCurrentFontInfo(handle); var newInfo = new CONSOLE_FONT_INFO_EX(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = TMPF_TRUETYPE; newInfo.FaceName = fontName; newInfo.dwFontSize.X = xSize ?? info.dwFontSize.X; newInfo.dwFontSize.Y = ySize ?? info.dwFontSize.Y; newInfo.FontWeight = weight ?? info.FontWeight; SetCurrentConsoleFontEx(handle, false, ref newInfo); }
public static void SetConsoleParameters() { Console.Title = "Job Assistant"; Console.CursorVisible = false; CONSOLE_FONT_INFO_EX ConsoleFontInfo = new CONSOLE_FONT_INFO_EX(); Console.OutputEncoding = System.Text.Encoding.UTF8; ConsoleFontInfo.cbSize = (uint)Marshal.SizeOf(ConsoleFontInfo); ConsoleFontInfo.FaceName = "Source Code Pro"; ConsoleFontInfo.dwFontSize.X = 10; ConsoleFontInfo.dwFontSize.Y = 20; SetCurrentConsoleFontEx(GetStdHandle(StdHandle.OutputHandle), false, ref ConsoleFontInfo); }
//TODO: Add SetFont method public static void SetFontSize(int width, int height) { CONSOLE_FONT_INFO_EX cfi = new CONSOLE_FONT_INFO_EX(); cfi.cbSize = (uint)Marshal.SizeOf(cfi); cfi.FaceName = ""; cfi.cbSize = (uint)Marshal.SizeOf(cfi); cfi.nFont = 0; cfi.dwFontSize = new COORD((short)width, (short)height); cfi.FontFamily = 0; cfi.FontWeight = 400; cfi.FaceName = "Consolas"; HandleError(!WinApi.SetCurrentConsoleFontEx(bufferHandle, false, ref cfi)); }
public static void SetConsoleFont(string fontName = "Terminal") { unsafe { IntPtr hnd = GetStdHandle(STD_OUTPUT_HANDLE); if (hnd != INVALID_HANDLE_VALUE) { CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX(); IntPtr ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.dwFontSize = new COORD(8, 8); newInfo.FontFamily = 0; newInfo.FontWeight = 0; newInfo.nFont = 0; SetCurrentConsoleFontEx(hnd, false, ref newInfo); } } }
private static unsafe void SetFont(string fontName, short x, short y) { IntPtr stdHandle = GetStdHandle(STD_OUTPUT_HANDLE); if (stdHandle != invalidHandle) { CONSOLE_FONT_INFO_EX info = new CONSOLE_FONT_INFO_EX { FontFamily = 0, dwFontSize = new COORD(x, y) }; info.cbSize = (uint)Marshal.SizeOf(info); Marshal.Copy(fontName.ToCharArray(), 0, new IntPtr(info.FaceName), fontName.Length); SetCurrentConsoleFontEx(stdHandle, false, ref info); } }
public Engine(short width = 240, short height = 80, string Title = "Console engine", short fontw = 12, short fonth = 12, bool showFps = true) { Width = width; Height = height; SetConsoleCP(437); SetConsoleOutputCP(437); buffer = new CharInfo[Width * Height]; rect = new SmallRect() { Left = 0, Top = 0, Right = Width, Bottom = Height }; Console.CursorVisible = false; Console.SetWindowPosition(0, 0); CONSOLE_FONT_INFO_EX ConsoleFontInfo = new CONSOLE_FONT_INFO_EX(); ConsoleFontInfo.cbSize = (uint)Marshal.SizeOf(ConsoleFontInfo); ConsoleFontInfo.FaceName = "Lucida Console"; ConsoleFontInfo.dwFontSize.X = fontw; ConsoleFontInfo.dwFontSize.Y = fonth; SetCurrentConsoleFontEx(GetStdHandle(STDOUT), false, ref ConsoleFontInfo); IntPtr inHandle = GetStdHandle(STDIN); uint mode = 0; GetConsoleMode(inHandle, ref mode); //mode &= ~ENABLE_QUICK_EDIT_MODE; mode |= (uint)ConsoleModes.ENABLE_WINDOW_INPUT; mode |= (uint)ConsoleModes.ENABLE_MOUSE_INPUT; mode &= ~(uint)ConsoleModes.ENABLE_QUICK_EDIT_MODE; SetConsoleMode(inHandle, mode); Console.SetWindowSize(width, height); Console.SetBufferSize(width, height); ShowFPS = showFps; Console.Title = Title; title = Title; }
public static SizeF MeasureString(string value, CONSOLE_FONT_INFO_EX fontInfoEx) { if (string.IsNullOrEmpty(value)) { return(SizeF.Empty); } if (fontInfoEx == null) { return(SizeF.Empty); } using (Font font = new Font(fontInfoEx.lpszFaceName, fontInfoEx.nWidth, fontInfoEx.nWeight.IsBold() ? FontStyle.Bold : FontStyle.Regular)) { using (Bitmap bmp = new Bitmap(1, 1, PixelFormat.Format32bppArgb)) { using (Graphics g = Graphics.FromImage(bmp)) { return(g.MeasureString(value, font)); } } } }
public static void SetConsoleFont(string fontName, short size) { unsafe { var hnd = GetStdHandle(StdHandle.OutputHandle); if (hnd != InvalidHandleValue) { var info = new CONSOLE_FONT_INFO_EX(); info.cbSize = (uint)Marshal.SizeOf(info); // Set console font to Lucida Console. var newInfo = new CONSOLE_FONT_INFO_EX(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = TmpfTrueType; IntPtr ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); // Get some settings from current font. newInfo.dwFontSize = new COORD(info.dwFontSize.X, size); SetCurrentConsoleFontEx(hnd, false, ref newInfo); } } }
private static unsafe void ChangeFontFromRasterToLucida() { Console.WriteLine("The following example shows how you can programmatically change the font from a raster font to Lucida Console."); string fontName = "Lucida Console"; IntPtr hnd = GetStdHandle(STD_OUTPUT_HANDLE); if (hnd != INVALID_HANDLE_VALUE) { CONSOLE_FONT_INFO_EX info = new CONSOLE_FONT_INFO_EX(); info.cbSize = (uint)Marshal.SizeOf(info); bool tt = false; // First determine whether there's already a TrueType font. if (GetCurrentConsoleFontEx(hnd, false, ref info)) { tt = (info.FontFamily & TMPF_TRUETYPE) == TMPF_TRUETYPE; if (tt) { Console.WriteLine("The console already is using a TrueType font."); return; } // Set console fonr to Lucida Console. CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = TMPF_TRUETYPE; IntPtr ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); //Get some settings from current font. newInfo.dwFontSize = new COORD(info.dwFontSize.X, info.dwFontSize.Y); newInfo.FontWeight = info.FontWeight; SetCurrentConsoleFontEx(hnd, false, newInfo); } } }
/// <summary> /// Changes the current console font and size (for Windows NT and up). /// </summary> /// <param name="font"></param> /// <param name="size"></param> public static unsafe void ChangeFont(FontFamily font, short size) { // if we are not on windows nt or later we return if (Environment.OSVersion.Platform != PlatformID.Win32NT) { return; } // sets console foreground color to default Console.ForegroundColor = ConsoleColor.Gray; // create out font details structure CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX(); // sets the size of the structure newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); // gets a pointer to the facename buffer IntPtr ptr = new IntPtr(newInfo.FaceName); // writes font family name to the buffer Marshal.Copy(fontFamilies[(int)font].ToCharArray(), 0, ptr, fontFamilies[(int)font].Length); // sets the font size newInfo.dwFontSize.y = size; // applies the font SetCurrentConsoleFontEx(handle, false, ref newInfo); }
static extern bool SetCurrentConsoleFontEx( IntPtr consoleOutput, bool maximumWindow, ref CONSOLE_FONT_INFO_EX consoleCurrentFontEx);
/// <summary> /// Функция проверки шрифта консоли и его замены (или предупреждения) /// </summary> private static unsafe void Refonting() { string fontName = "Consolas"; IntPtr hnd = GetStdHandle(STD_OUTPUT_HANDLE); if (hnd != INVALID_HANDLE_VALUE) { CONSOLE_FONT_INFO_EX info = new CONSOLE_FONT_INFO_EX(); info.cbSize = (uint)Marshal.SizeOf(info); bool tt = false; // First determine whether there's already a TrueType font. if (GetCurrentConsoleFontEx(hnd, false, ref info)) { tt = (info.FontFamily & TMPF_TRUETYPE) == TMPF_TRUETYPE; if (tt) { //Console.WriteLine("The console already is using a TrueType font."); return; } else Console.WriteLine("Please, check in console's \"Properties\" font \"Consolas\" for right result output.\n"); //// Set console font to Lucida Console. //CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX(); //newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); //newInfo.FontFamily = TMPF_TRUETYPE; //IntPtr ptr = new IntPtr(newInfo.FaceName); //Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); //// Get some settings from current font. //newInfo.dwFontSize = new COORD(info.dwFontSize.X, info.dwFontSize.Y); //newInfo.FontWeight = info.FontWeight; //try //{ // ///SetCurrentConsoleFontEx(hnd, false, newInfo); //} //catch (AccessViolationException e) //{ // Console.WriteLine("Error: attempt to write protected memory.\nPlease, check in console's \"Properties\" font \"Consolas\" for right result output.\n"); //} } } }
static extern bool GetCurrentConsoleFontEx( IntPtr consoleOutput, bool maximumWindow, ref CONSOLE_FONT_INFO_EX lpConsoleCurrentFontEx);
public static unsafe void SetConsoleFont(string fontName, int xSize, int ySize) { var hnd = WinCon.GetStdHandle(WinCon.STD_OUTPUT_HANDLE); var newInfo = new CONSOLE_FONT_INFO_EX { cbSize = 84, FontFamily = 48 }; var ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); newInfo.dwFontSize = new CoordInternal(xSize, ySize); newInfo.FontWeight = 400; WinCon.SetCurrentConsoleFontEx(hnd, false, ref newInfo); }
public static extern bool SetCurrentConsoleFontEx( IntPtr ConsoleOutput, bool MaximumWindow, CONSOLE_FONT_INFO_EX ConsoleCurrentFontEx );
public static extern Int32 SetCurrentConsoleFontEx( IntPtr ConsoleOutput, bool MaximumWindow, ref CONSOLE_FONT_INFO_EX ConsoleCurrentFontEx);
public static bool IsConsoleFontTrueType() { CONSOLE_FONT_INFO_EX fontInfoEx = GetCurrentFontEx(); return(fontInfoEx != null && fontInfoEx.nFamily.FastHasFlag(FontMask.TRUETYPE_FONTTYPE)); }
public static bool SetCurrentFontEx([NotNull] CONSOLE_FONT_INFO_EX fontInfoEx) { IntPtr hConsole = GetOutputHandle(); return(!hConsole.IsInvalidHandle() && Win32.SetCurrentConsoleFontEx(hConsole, false, ref fontInfoEx)); }