C # Set the font color in the console

Source: Internet
Author: User

A program has been developed over the past few days, and the program itself is very simple. The general function is to enter query conditions, and retrieve results from the database for calculation and display. However, you must use the console to implement functions. Because of its simple functions, the program was quickly completed. When demonstrating the program for users, I suddenly felt that the display of the program was unfriendly and it was all black and white. Although the functional demonstration required by the user is successful, the font color in the console looks uncomfortable when too many results are displayed. After the demo, you are ready to modify the font color. After searching through the internet, we found that the implementation in C # is very simple, and only a few lines of code are required.

The Code is as follows:

Console. BackgroundColor = ConsoleColor. Blue; // you can specify the background color.
Console. ForegroundColor = lelecolor. White; // set the foreground color, that is, the font color.
Console. WriteLine ("the first line is white blue .");

Console. ResetColor (); // set the foreground color and background color of the Console to the default value.
Console. BackgroundColor = ConsoleColor. Green;
Console. ForegroundColor = ConsoleColor. DarkGreen;
String value = "the third line is green and dark green ";
Console. WriteLine (value. PadRight (Console. WindowWidth-value.Length); // you can specify the background color for the entire row.

The display effect is as follows:

Displays the background color and foreground color supported in the console.

Type type = Console. ForegroundColor = (name Console. BackgroundColor = Console. BackgroundColor = (name Console. ForegroundColor =}

Fonts supported in the console

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.