Click here to Skip to main content
14,971,209 members
Articles / DevOps
Article
Posted 10 Nov 2015

Stats

34.7K views
2.8K downloads
29 bookmarked

Console Control

Rate me:
Please Sign up or sign in to vote.
4.94/5 (22 votes)
8 Jul 2016CPOL
A Winforms control that looks like a console screen, with full reading and writing support.

Download binaries 

Download source 

Image 1

Introduction

Recently, I was working on a project where I needed to create a WinForms application, but I needed a sort of "Console Window". Not finding anything I liked, I decided to write my own. The console control presented here is built completely from scratch, without using any existing controls and it does all its own rendering.

Using the code

To use the control, simply reference the DLL or project from your own project. After referencing it, you should be able to see it in the designer window. Simply drag an instance out to your form. You can set the following properties:

ShowCursor - True/False. If true, the cursor will be displayed on the console window. If false, then no cursor will be displayed.

CursorType - Enumeration. If set to Underline, then the cursor will be rendered as an underline. If set to Block, then the cursor will be rendered as a block. If set to Invisible, then the cursor will be invisible.

AllowInput - True/False. If set to true, then the console window will capture keystrokes and emit the LineEntered event (see below).

EchoInput - True/False. If set to true, then anytime a key is pressed, the console window will echo the key pressed to the console window.

ConsoleBackgroundColor - Color. This property determines the background color of the console window. The default is black.

ConsoleForegroundColor - Color. This property determines the foreground color of the console window. The default is gray.

CurrentBackgroundColor - Color. This property determines the background color of any text that's printed out to the console window.

CurrentForegroundColor - Color. This property determines the foreground color of any text that's printed out to the console window.

The following methods are available:

SetCursorPosition() - Sets the row and column of the cursor.

GetCursorPosition() - Returns the row and column of the cursor.

Write() - Writes a string or character or newline at the current cursor position, using the current background and foreground color or you can specify an implicit foreground and background color.

ScrollUp() - Scrolls the console window up 1 or more lines.

Clear() - Clears the console window completely and places the cursor in the upper left corner.

SetBackgroundColorAt() - Sets the background color at the specified location to the specified color.

SetForegroundColorAt() - Sets the foreground color at the specified location to the specified color.

SetCharacterAt() - Places a character at the specified location.

 

History

11/10/2015 - Initial Release

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

icemanind
Web Developer http://www.icemanind.com
United States United States
No Biography provided

Comments and Discussions

 
SuggestionSmall code changes, to change control size Pin
parmando31-Mar-20 8:44
Memberparmando31-Mar-20 8:44 
QuestionVery good, thank. Pin
sapwood5-Dec-19 19:21
Membersapwood5-Dec-19 19:21 
QuestionHow to change the size? Pin
Flux OS9-Aug-18 1:33
MemberFlux OS9-Aug-18 1:33 
GeneralPlease show and explain the code Pin
PIEBALDconsult9-Jul-16 18:20
professionalPIEBALDconsult9-Jul-16 18:20 
QuestionAn alternative... Pin
Marc Clifton9-Jul-16 8:36
mvaMarc Clifton9-Jul-16 8:36 
GeneralRe: An alternative... Pin
PIEBALDconsult9-Jul-16 9:31
professionalPIEBALDconsult9-Jul-16 9:31 
GeneralRe: An alternative... Pin
Marc Clifton9-Jul-16 10:21
mvaMarc Clifton9-Jul-16 10:21 
PraiseNice Pin
ArpitNagar9-Jul-16 8:16
MemberArpitNagar9-Jul-16 8:16 
GeneralMy vote of 5 Pin
Franc Morales8-Jul-16 23:44
MemberFranc Morales8-Jul-16 23:44 
PraiseExcellent... Pin
klinkenbecker25-Apr-16 15:07
Memberklinkenbecker25-Apr-16 15:07 
PraiseVery nice Pin
MichaelC#Noob12-Nov-15 6:25
professionalMichaelC#Noob12-Nov-15 6:25 
Questionshell replacement? Pin
John Torjo10-Nov-15 19:49
professionalJohn Torjo10-Nov-15 19:49 
AnswerRe: shell replacement? Pin
icemanind11-Nov-15 5:52
Membericemanind11-Nov-15 5:52 
GeneralRe: shell replacement? Pin
John Torjo11-Nov-15 18:39
professionalJohn Torjo11-Nov-15 18:39 

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

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