在.NET中的控制台窗口中更改字体
我已经构建了一个简洁的控制台应用程序,该应用程序基本上可以与用户计算机上的ASP.NET项目进行交互。我确实有一个琐碎的需求,我需要做的就是在显示控制台窗口之前,先将其设置为黑色背景,柠檬绿色的前景和Lucida字体。我可以通过使用Console类的静态方法来实现颜色部分。尽管该课程中没有任何内容涉及更改字体?有没有人能够以编程方式更改控制台字体?
I have built a neat little Console app which basically interacts with ASP.NET projects on a users machine. I have a really trivial need, all I need to do is before I show the Console window, I need to have it a black background, a lime green foreground and a Lucida font. I could achieve the color part by using the static methods of Console class. Although there is nothing in the class which talks about changing fonts? Has anyone been able to change Console font programatically?
任何帮助表示赞赏。
请不要在打算供其他用户使用的应用程序上执行此操作,除非他们要求此功能。 Consolas是我系统上控制台的唯一字体:p
Please don't do that on an application that is meant to be used from other users, unless they request this feature. Consolas is the only font for consoles on my system :p
您可以尝试更改打开控制台(或可执行文件)的链接的属性,但是如果我是对的话,请选择本地设置。如果仅用于在系统上运行应用程序,则可能是您想要的。我不确定您如何以编程方式更改它们。
You can try to change the properties of the link that opens the console (or the executable), but that is a local setting if I'm right. This is likely the thing you want if it's just for running the app on your system. I'm not sure how you can change these programmatically.
自Vista以来,就有 SetCurrentConsoleFontEx
,它可以做什么?如果需要,可以使它与Console类一起使用。我是否提到过,如果该应用程序出现在我的系统中,我会为此而讨厌您吗? ;)
Since Vista, there's SetCurrentConsoleFontEx
, which may do what you want, if you can get it to work with the Console class. Did I mention I will hate you for that if the app ever comes to my system? ;)