Click here to Skip to main content
Click here to Skip to main content

Get colors in your VB.NET console application

, 17 Jul 2003
Rate this:
Please Sign up or sign in to vote.
Use Windows APIs to write a console tool module, able to change your console background and foreground colors.
<!-- Article image -->

Sample Image - color_console.jpg

<!-- Add the rest of your HTML here -->

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

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

About the Author

ps1k0
Web Developer
France France
Actually software architect for a little company based in France (Rennes), I'm specialized in distributed applications. I work a lot with .net remoting but don't have enough time to write articles about it ...:(

Comments and Discussions

 
Generalthanks! Pinmemberjosephlawrencecarpio23-Mar-08 15:41 
GeneralSmall bug PinmemberPhiL6667-Dec-06 15:25 
GeneralRe: Small bug Pinmembermadestro13-Dec-06 7:14 
SuggestionRe: Small bug PinmemberWilfredo Gumersindo6-Sep-11 5:32 
GeneralAstonishing Pinmembernalt6519-Jan-06 21:53 
GeneralCreata, but litle Error using Option Strict Pinmemberheck-17-Nov-05 21:18 
GeneralConsole Code Colors Pinmemberbrichard23-Jun-04 11:14 
QuestionIcons? PinsitebuilderUwe Keim18-Jul-03 0:55 
AnswerRe: Icons? PinmemberRoger J18-Aug-03 22:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 18 Jul 2003
Article Copyright 2003 by ps1k0
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid