Changing font in a Console window in .NET

懵懂的女人 提交于 2019-11-27 21:57:17

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!