المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Changing Console font



C# Programming
01-03-2011, 02:34 PM
I want to change the font size of the Console but that is not easy. After googling, the WinAPI SetCurrentConsoleFontEx() located in the kernel32.dll should do the trix. This is my code:

using System;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace ConsoleApplication1
{
class Program
{
[StructLayout(LayoutKind.Sequential)]
public struct COORD
{
public short X;
public short Y;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_FONT_INFO_EX
{
public uint cbSize;
public uint nFont;
public COORD dwFontSize;
public ushort FontFamily;
public ushort FontWeight;

// todo: this isn't right, needs fixing
//WCHAR FaceName[LF_FACESIZE];
string FaceName;
}

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetCurrentConsoleFontEx(IntPtr ConsoleOutput, bool MaximumWindow, CONSOLE_FONT_INFO_EX ConsoleCurrentFontEx);

static void Main(string[] args)
{
CONSOLE_FONT_INFO_EX font = new CONSOLE_FONT_INFO_EX();
//<span class="code-comment"> font.cbSize = //