Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing font in a Console window in .NET

Tags:

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.

like image 396
theraneman Avatar asked Nov 26 '09 09:11

theraneman


People also ask

How do I change font in Visual Studio console?

In VSC 2019 go to File -> Preferences -> Settings -> Features -> Terminal and find option of font-size and change to apropriate value for your needs.


2 Answers

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

like image 134
OregonGhost Avatar answered Sep 27 '22 22:09

OregonGhost


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.

like image 24
Paul Turner Avatar answered Sep 27 '22 22:09

Paul Turner