コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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))
            });
        }
コード例 #3
0
ファイル: ConsoleFontHelper.cs プロジェクト: FuJa0815/MyChess
        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);
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
ファイル: ConsoleFontHelper.cs プロジェクト: FuJa0815/MyChess
 private static extern bool SetCurrentConsoleFontEx(
     IntPtr consoleOutput,
     bool maximumWindow,
     ref ConsoleFontInfoEx consoleCurrentFontEx);
コード例 #6
0
ファイル: NativeMethods.cs プロジェクト: Koneke/DeepMagic
		internal static extern bool SetCurrentConsoleFontEx(
			IntPtr consoleOutput, 
			bool maximumWindow,
			ConsoleFontInfoEx consoleCurrentFontEx);
コード例 #7
0
        /// <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));
        }
コード例 #8
0
        /// <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));
        }