views:

341

answers:

3

Hi guys,

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.

A: 

The console window is a pretty basic environment. If you want to change the font, you will need to upgrade to a Windows application.

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

Programming Hero
This is only partially true. You can't change the font for single characters, but you can for the entire console.
OregonGhost
If you see the properties window for a Console, there are 2 fonts available. Why would the .NET framework not be able to change the font and be able to change colors!
theraneman
@OregonGhost: Can you let me know how would change the font programatically for the entire Console then?
theraneman
@theraneman: Because the color is changed by putting codes in the output of your program, whereas the font is changed by changing the settings of `cmd.exe`. The two are vastly different.
Matthew Scharley
Console.ForegroundColor changes the color of the following output, not of the entire console window. This is different from setting the default console color from the console properties page.
OregonGhost
@theraneman: Go read my answer. I don't know though how you can change the console properties programmatically (maybe via registry access), but the option I mentioned may be all you need anyway.
OregonGhost
@OregonGhost: Thanks for that info, much appreciated.
theraneman
+2  A: 

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

OregonGhost
Lol. I am not going to let you use my little Super app :). In that case, I should not even change the colors then.
theraneman
Not in general, but colors can also be use to improve formatting (like PowerShell does, for example, with errors in red) :)
OregonGhost
+3  A: 

Is this article answer to your question?

Alex
Thanks Alex, I guess that Pavel guy had the exact same problem I have :). I am so addicted to StackOverflow now that I care a little less to search on the Internet myself :).
theraneman
+1. Thanks. Alex.
Fábio Antunes