• Advertisement
Sign in to follow this  

Console Effects in C#

This topic is 4718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I am making a console game (C#) right now, but, as you all know, it looks really dull. I've seen once a console game with different colours, different fonts etc., so that it looked really cool. Is there a way to use these effects in C#? Different colours, fonts...? And are there any ways to make your console look nice? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
To change the text colour you can import SetConsoleTextAttribute from the kernel32.dll file.

example:

using System.Runtime.InteropServices; //need to add this on top



const int STD_OUTPUT_HANDLE = -11;
const int FOREGROUND_BLUE = 0x0001;
const int FOREGROUND_GREEN = 0x0002;
const int FOREGROUND_RED = 0x0004;
const int FOREGROUND_INTENSITY = 0x0008;

[DllImport("kernel32.dll")]
static extern IntPtr GetStdHandle(int std);
[DllImport("kernel32.dll")]
static extern bool SetConsoleTextAttribute(IntPtr handle,int att);

static void ChangeCol(int c)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c);
}

static void Main(string[] args)
{
ChangeCol(FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
Console.WriteLine("foobar");
}




Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement