Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Get colors in your VB.NET console application

0.00/5 (No votes)
17 Jul 2003 1  
Use Windows APIs to write a console tool module, able to change your console background and foreground colors.

Sample Image - color_console.jpg

Introduction

How can i use colors to make my console application look pretty with VB.NET ? I was writing a remoting server when this idea came ... So i've made this little module ! It was not really difficult to do but i think it could save your time ;)

How to use it ?

You can either change background and foregroud ...

ConsoleTools.SetConsoleColors(ConsoleColor.Green, ConsoleColor.DarkBlue)

... or just foreground :

ConsoleTools.SetConsoleColors(ConsoleColor.Pink) 

How does it run ?

I just use kernel api's SetConsoleTextAttribute (to change colors) and GetStHandle (to retrieve console output handles). An enumeration has been created to have bases colors codes : enumeration values must be directly used to change foreground color, and enumeration values * 16 (mask) must be used to change foreground color.

So you just have now to use SetConsoleColors function (which use kernel's api) to change your console colors ...

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here