Click here to Skip to main content
Licence 
First Posted 17 Jul 2003
Views 84,148
Bookmarked 30 times

Get colors in your VB.NET console application

By | 17 Jul 2003 | Article
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

About the Author

ps1k0

Web Developer

France France

Member

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 ...:(

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalthanks! Pinmemberjosephlawrencecarpio15:41 23 Mar '08  
GeneralSmall bug PinmemberPhiL66615:25 7 Dec '06  
GeneralRe: Small bug Pinmembermadestro7:14 13 Dec '06  
SuggestionRe: Small bug PinmemberWilfredo Gumersindo5:32 6 Sep '11  
GeneralAstonishing Pinmembernalt6521:53 19 Jan '06  
GeneralCreata, but litle Error using Option Strict Pinmemberheck-21:18 17 Nov '05  
GeneralConsole Code Colors Pinmemberbrichard11:14 23 Jun '04  
QuestionIcons? PinsitebuilderUwe Keim0:55 18 Jul '03  
AnswerRe: Icons? PinmemberRoger J22:13 18 Aug '03  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 18 Jul 2003
Article Copyright 2003 by ps1k0
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid