Sign in to follow this  
Zodiak

Console Effects in C#

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this