Copy codeThe Code is as follows: using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace ConsoleApplication1
{
Class Program
{
Static void Main (string [] args)
{
Bool isBreak = false;
Lelecolor colorBack = Console. BackgroundColor;
Lelecolor colorFore = Console. ForegroundColor;
// The first line of information
Console. WriteLine ("******* now working ...******");
// Draw the progress bar background in the second row
Console. BackgroundColor = ConsoleColor. DarkCyan;
For (int I = 0; ++ I <= 25 ;)
{
Console. Write ("");
}
Console. WriteLine ("");
Console. BackgroundColor = colorBack;
// Output progress in the third row
Console. WriteLine ("0% ");
// Output a prompt in the fourth row. Press enter to cancel the current progress.
Console. WriteLine ("<Press Enter To Break.> ");
// ----------------------- A complete work area is drawn on the top.
// Start to control the progress bar and progress changes
For (int I = 0; ++ I <= 100 ;)
{
// Check whether a key request exists. If yes, check whether it is a return key. If yes, exit the loop.
If (Console. KeyAvailable & System. Console. ReadKey (true). Key = lelekey. Enter)
{
IsBreak = true; break;
}
// Draw the progress bar
Console. BackgroundColor = lelecolor. Yellow; // you can specify the progress bar color.
Console. SetCursorPosition (I/4, 1); // set the cursor position. The parameter is the column number and the row number.
Console. Write (""); // move the progress bar
Console. BackgroundColor = colorBack; // restore the output color
// Update Progress percentage. The principle is the same as above.
Console. ForegroundColor = ConsoleColor. Green;
Console. SetCursorPosition (0, 2 );
Console. Write ("{0 }%", I );
Console. ForegroundColor = colorFore;
// Simulate the delay in actual work; otherwise, the progress is too fast.
System. Threading. Thread. Sleep (100 );
}
// After the work is completed, the information is output based on the actual situation, and the information indicating exit is clearly displayed.
Console. SetCursorPosition (0, 3 );
Console. Write (isBreak? "Break !!! ":" Finished .");
Console. WriteLine ("");
// Wait for exit
Console. ReadKey (true );
}
}
}