且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

控制台应用程序字体大小

更新时间:2023-01-27 20:12:58

其中一个例子 [ ^ ]显示如何更改控制台字体。
One of the examples on this page[^] shows how to change the console font.


我右键单击控制台窗口和属性。那里你可以改变字体大小。
I right clicked on console windows and Properties. There You can change font size.


在C ++中你可以查看

SetCurrentConsoleFontEx [ ^ ]



在C#中你可以使用这个



In C++ you can check out the
SetCurrentConsoleFontEx[^]

In C# you can use this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;

namespace ConsoleExtender {
	[StructLayout(LayoutKind.Sequential, Pack = 1)]
	public struct ConsoleFont {
		public uint Index;
		public short SizeX, SizeY;
	}

	public static class ConsoleHelper {
		[DllImport("kernel32")]
		public static extern bool SetConsoleIcon(IntPtr hIcon);

		public static bool SetConsoleIcon(Icon icon) {
			return SetConsoleIcon(icon.Handle);
		}

		[DllImport("kernel32")]
		private extern static bool SetConsoleFont(IntPtr hOutput, uint index);

		private enum StdHandle {
			OutputHandle = -11
		}

		[DllImport("kernel32")]
		private static extern IntPtr GetStdHandle(StdHandle index);

		public static bool SetConsoleFont(uint index) {
			return SetConsoleFont(GetStdHandle(StdHandle.OutputHandle), index);
		}

		[DllImport("kernel32")]
		private static extern bool GetConsoleFontInfo(IntPtr hOutput, [MarshalAs(UnmanagedType.Bool)]bool bMaximize, 
			uint count, [MarshalAs(UnmanagedType.LPArray), Out] ConsoleFont[] fonts);

		[DllImport("kernel32")]
		private static extern uint GetNumberOfConsoleFonts();

		public static uint ConsoleFontsCount {
			get {
				return GetNumberOfConsoleFonts();
			}
		}

		public static ConsoleFont[] ConsoleFonts {
			get {
				ConsoleFont[] fonts = new ConsoleFont[GetNumberOfConsoleFonts()];
				if(fonts.Length > 0)
					GetConsoleFontInfo(GetStdHandle(StdHandle.OutputHandle), false, (uint)fonts.Length, fonts);
				return fonts;
			}
		}

	}
}





你应该带在你的注册表中查看



You should take a look in your registry at

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont



以找出您的计算机可以支持的字体。


to find out what fonts your computer can support.