public static Size GetConsoleFontSize() { IntPtr outHandle = NativeMethods.CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); int errorCode = Marshal.GetLastWin32Error(); if (outHandle.ToInt32() == INVALID_HANDLE_VALUE) { throw new IOException("Unable to open CONOUT$", errorCode); } var cfi = new ConsoleFontInfo(); if (!NativeMethods.GetCurrentConsoleFont(outHandle, false, cfi)) { throw new InvalidOperationException("Unable to get font information."); } return(new Size(cfi.dwFontSize.X, cfi.dwFontSize.Y)); }
public static extern bool GetCurrentConsoleFont( IntPtr hConsoleOutput, bool bMaximumWindow, [Out][MarshalAs(UnmanagedType.LPStruct)] ConsoleFontInfo lpConsoleCurrentFont);