Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Touring Whidbey's Base Class Library Enhancements : Page 5

The core API set underpinning managed application development in .NET—the Base Class Libraries (BCL)—have received several notable additions in the Whidbey release. Find out performance-based improvements, class-oriented feature additions, and the introduction of previously missing functionality through entirely new classes.


advertisement
Not Your Grandpa's Console
The BCL class that gains the most new features is the Console class. Prior to the new features, the Console class allowed limited input and output buffer access, and interactions limited to very linear scenarios. Reading and writing task interactions with the screen buffer were dictated by the simple Read, Write, ReadLine, and WriteLine methods.

Enhancements to the Console class enable complete control over positioning of the cursor, foreground and background colors, and the ability to move sections of text, including color scheme, around the screen buffer. Moving text around the screen buffer eliminates the need to manually reconstruct the information in the screen buffer at the new location. The new properties supported by the Console class, shown in Table 3, allow extensive abilities to manipulate the buffer screen characteristics. The possible color choices have been expand to 16 choices.

Table 3: Numerous new Console class properties provide significantly enhanced features for console-based applications.

Console Property name

Description



BackgroundColor

Modifies the background color of the console

BufferHeight

Gets the current height of the buffer area

BufferWidth

Gets the current width of the buffer area

CursorLeft

Gets the current column position of the cursor

CursorSize

Modifies the current size of the cursor

CursorTop

Gets the current row position of the cursor

CursorVisible

Modifies whether the cursor is visible

ForegroundColor

Modifies the foreground color of the console

KeyAvailable

Indicates whether a key has been pressed

Title

Modifies the title of the console title bar

TreatControlCAsInput

Modifies whether (CTRL+C) is treated as ordinary user input to be processed by the Console class or handled by the operating system as a program execution interruption. If set to False, the CancelKeyPress event can be used to process (CTRL+C).

WindowHeight

Gets the current height of the console window area

WindowLeft

Gets the current leftmost position of the console window area relative to the screen buffer

WindowTop

Gets the current top position of the console window area relative to the screen buffer

WindowWidth

Gets the current width of the console window


The Console class gains numerous methods and a new event. You can call the Beep method to issue a system beep. You can call the Clear method to move the cursor to the upper-left corner and clear the screen buffer using the current values of the ForegroundColor and BackgroundColor properties. Call the ResetColor method to revert back to the default console color scheme. You can call the SetBufferSize method to programmatically control the size of the screen buffer and call MoveBufferArea to reallocate characters and their current color scheme from one section of the screen buffer to another without manually reconstructing the screen buffer section affected. You use a combination of the KeyAvailable property and the ReadKey method to grab user input character by character without blocking the executing thread. You handle the CancelKeyPress event to perform complex logic in response to the user typing Ctrl-C.

The enhancements to the Console class provide significantly increased options for developing highly interactive console-based applications that are far more visually appealing than the traditional console-based application. These applications don't have the overhead associated with moving to a full-blown graphical-based user interface provided by Windows Forms-based applications.

An example of many of these features in action together is shown in Figure 4, and the complete code listing is in Listing 1.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Thanks for your registration, follow us on our social networks to keep up-to-date