相关疑难解决方法(0)

SetCurrentConsoleFontEx不适用于长字体名称

我不能让这个用于16个字符或更长的字体名称,但控制台本身显然没有这个限制.有没有人知道一种程序化的方式来设置与内置的"Lucida Sans打字机"或开源"Fira Code Retina"一起使用的字体?

以下代码有效:

我从各个地方复制了PInvoke代码,特别是PowerShell控制台主机和Microsoft Docs

请注意,CONSOLE_FONT_INFOEX和SetCurrentConsoleFontEx的相关文档没有谈到这一点,结构将字体定义为大小为32的WCHAR字段...

还要注意什么不是限制,而是是从控制台对话框的限制,是字体必须有真正的类型列出,而且必须是真正的固定宽度.使用此API,您可以选择"Times New Roman"等可变宽度字体...

但是,在API中,名称中必须少于 16个字符 - 这是控制台本身没有的限制,可能是API中的错误而不是我的下面的代码

using System;
using System.Runtime.InteropServices;

public static class ConsoleHelper
{
    private const int FixedWidthTrueType = 54;
    private const int StandardOutputHandle = -11;

    [DllImport("kernel32.dll", SetLastError = true)]
    internal static extern IntPtr GetStdHandle(int nStdHandle);

    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
    internal static extern bool SetCurrentConsoleFontEx(IntPtr hConsoleOutput, bool MaximumWindow, ref FontInfo ConsoleCurrentFontEx);

    [return: MarshalAs(UnmanagedType.Bool)] …
Run Code Online (Sandbox Code Playgroud)

c# windows console powershell pinvoke

6
推荐指数
1
解决办法
253
查看次数

如何在Console App中更改Console.Writeline(文本)输出文本字体大小

例如,我们有"Hello World!"等文字.我使用Console.Writeline("HelloWorld!")和"HelloWorld!" 在控制台应用程序中打印.有没有办法打印"HelloWorld!" 在控制台应用程序更大?

c# console-application

5
推荐指数
1
解决办法
5万
查看次数

C#.NET控制台应用程序使用的控制台字体和布局

我如何设置Windows(或Visual Studio,或我的应用程序),以便当我通过从Visual Studio 2010中按F5运行控制台应用程序时,我可以使用我选择的字体而不是80x25标准CMD/DOS获得120x50布局窗口?

(甚至更好 - 有谁知道如何让VS在Console2或bash而不是cmd.exe中运行控制台应用程序?)

c# console layout cmd visual-studio-2010

4
推荐指数
1
解决办法
7263
查看次数