相关疑难解决方法(0)

在C#中更改控制台窗口中的字体

我有一个用C#编写的程序,它使用Raster字体中不可用的字符.所以我想将字体更改为Lucida Console.

若要以编程方式更改Console字体,我使用此代码的SetCurrentConsoleFontEx()(源:MSDN控制台类)但我在调用SetCurrentConsoleFontEx()时遇到System.AccessViolationException.

谁能帮助我?

谢谢你的帮助.

using System;
using System.Linq;
using System.Runtime.InteropServices;


namespace ConsoleExtender 
{
  public static class ConsoleHelper
  {
      [StructLayout(LayoutKind.Sequential)]
      internal unsafe struct CONSOLE_FONT_INFO_EX
      {
          internal uint cbSize;
          internal uint nFont;
          internal COORD dwFontSize;
          internal int FontFamily;
          internal int FontWeight;
          internal fixed char FaceName[LF_FACESIZE];
      }

      [StructLayout(LayoutKind.Sequential)]
      internal struct COORD
      {
          internal short X;
          internal short Y;

          internal COORD(short x, short y)
          {
              X = x;
              Y = y;
          }
      }
      [DllImport("kernel32.dll", SetLastError = true)]
      static extern IntPtr GetStdHandle(int …
Run Code Online (Sandbox Code Playgroud)

.net c# console fonts

7
推荐指数
2
解决办法
7085
查看次数

标签 统计

.net ×1

c# ×1

console ×1

fonts ×1