开发者

Changing font in a Console window in .NET

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?

Any help appreciated.


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.

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? ;)


The console window is a pretty basic environment. Whilst it's possible to change the font in most recent versions of Windows using unmanaged Win32 API calls, it's not supported through a managed API.

Font colour, however, can be set using the Console.ForegroundColor property.

Arguably, you shouldn't be trying to exert so much control over a console window as it's intended to be a simple text-only interface. If you want to have absolute control over the typeface used, you should consider upgrading to a Windows application, as this will let you trivially create a text window and do whatever you want to the fonts and colours in use.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜