/// <summary> /// Set the font for the console. /// </summary> /// <param name="faceName"> /// The name of a TrueType font face. Pass a Null or empty string for 'raster'. /// </param> /// <param name="fontSize">The font size (points).</param> /// <param name="bold"> /// Indicates if a bold font should be used. /// </param> /// <returns>True, if the console font is set correctly; otherwise false.</returns> public static bool SetCurrentConsoleFont(string faceName, ushort fontSize, bool bold) { IntPtr hnd = GetStdHandle(STD_OUTPUT_HANDLE); if (string.IsNullOrWhiteSpace(faceName)) { if (SelectFirstTrueTypeFont()) { faceName = GetCurrentConsoleFont().FaceName; } } if (hnd != INVALID_HANDLE_VALUE) { // Set console font. ConsoleFontInfoEx newInfo = new ConsoleFontInfoEx { FontSize = new Coord(0, (short)fontSize), FontWeight = bold ? 700 : 400, FaceName = faceName, Size = (uint)Marshal.SizeOf(typeof(ConsoleFontInfoEx)) }; return(SetCurrentConsoleFontEx(hnd, false, ref newInfo)); } return(false); }
/// <summary> /// Gets the font information for the current console font. /// </summary> /// <returns>A structure containing console font information.</returns> public static ConsoleFontInfoEx GetCurrentConsoleFont() { IntPtr hnd = GetStdHandle(STD_OUTPUT_HANDLE); if (hnd != INVALID_HANDLE_VALUE) { ConsoleFontInfoEx info = new ConsoleFontInfoEx(); info.Size = (uint)Marshal.SizeOf(info); if (GetCurrentConsoleFontEx(hnd, false, ref info)) { return(info); } } return(new ConsoleFontInfoEx { Size = (uint)Marshal.SizeOf(typeof(ConsoleFontInfoEx)) }); }
public static unsafe void SetConsoleFont(string fontName) { var hnd = GetStdHandle(StdOutputHandle); if (hnd == InvalidHandleValue) { return; } var newInfo = new ConsoleFontInfoEx(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = TmpfTruetype; var ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); // Get some settings from current font. newInfo.dwFontSize = new Coordinate((short)FontSize, (short)FontSize); newInfo.FontWeight = FontSize; SetCurrentConsoleFontEx(hnd, false, ref newInfo); }
public static void SetConsoleFont(string fontName, short fontSize) { unsafe { var hnd = GetStdHandle(StdOutputHandle); if (hnd != InvalidHandleValue) { var info = new ConsoleFontInfoEx(); info.cbSize = (uint)Marshal.SizeOf(info); var newInfo = new ConsoleFontInfoEx(); newInfo.cbSize = (uint)Marshal.SizeOf(newInfo); newInfo.FontFamily = TmpfTruetype; var ptr = new IntPtr(newInfo.FaceName); Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length); newInfo.dwFontSize = new Coord(info.dwFontSize.X, fontSize /*info.dwFontSize.Y*/); newInfo.FontWeight = info.FontWeight; SetCurrentConsoleFontEx(hnd, false, ref newInfo); } } }
private static extern bool SetCurrentConsoleFontEx( IntPtr consoleOutput, bool maximumWindow, ref ConsoleFontInfoEx consoleCurrentFontEx);
internal static extern bool SetCurrentConsoleFontEx( IntPtr consoleOutput, bool maximumWindow, ConsoleFontInfoEx consoleCurrentFontEx);
/// <summary> /// Set the font for the console. /// </summary> /// <param name="faceName"> /// The name of a TrueType font face. Pass a Null or empty string for 'raster'. /// </param> /// <param name="bold"> /// Indicates if a bold font should be used. /// </param> /// <returns>True, if the console font is set correctly; otherwise false.</returns> public static bool SetCurrentConsoleFont(string faceName, bool bold) { ConsoleFontInfoEx info = GetCurrentConsoleFont(); return(SetCurrentConsoleFont(faceName, (ushort)info.FontSize.Y, bold)); }
/// <summary> /// Set the font for the console. /// </summary> /// <param name="faceName"> /// The name of a TrueType font face. Pass a Null or empty string for 'raster'. /// </param> /// <param name="fontSize">The font size (points).</param> /// <returns>True, if the console font is set correctly; otherwise false.</returns> public static bool SetCurrentConsoleFont(string faceName, ushort fontSize) { ConsoleFontInfoEx info = GetCurrentConsoleFont(); return(SetCurrentConsoleFont(faceName, fontSize, false)); }