C\#콘 솔 출력 진도 와 백분율 의 인 스 턴 스 코드

2772 단어 진도퍼센트

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;

 namespace ConsoleApplication1
 {
     class Program
     {
         static void Main(string[] args)
         {
             bool isBreak = false;
             ConsoleColor colorBack = Console.BackgroundColor;
             ConsoleColor colorFore = Console.ForegroundColor;

             //            
             Console.WriteLine("****** now working...******");

             //            
             Console.BackgroundColor = ConsoleColor.DarkCyan;
             for (int i = 0; ++i <= 25; )
             {
                 Console.Write(" ");
             }
             Console.WriteLine(" ");
             Console.BackgroundColor = colorBack;

             //            
             Console.WriteLine("0%");
             // ,            
             Console.WriteLine("<Press Enter To Break.>");
             //----------------------- ,

             //            
             for (int i = 0; ++i <= 100; )
             {
                 // , , ,                
                 if (Console.KeyAvailable && System.Console.ReadKey(true).Key == ConsoleKey.Enter)
                 {
                     isBreak = true; break;
                 }
                 //                 
                 Console.BackgroundColor = ConsoleColor.Yellow;//                
                 Console.SetCursorPosition(i / 4, 1);// ,                
                 Console.Write(" ");//                
                 Console.BackgroundColor = colorBack;//                
                 // , .               
                 Console.ForegroundColor = ConsoleColor.Green;
                 Console.SetCursorPosition(0, 2);
                 Console.Write("{0}%", i);
                 Console.ForegroundColor = colorFore;
                 // ,                
                 System.Threading.Thread.Sleep(100);
             }
             // , ,            
             Console.SetCursorPosition(0, 3);
             Console.Write(isBreak ? "break!!!" : "finished.");
             Console.WriteLine(" ");
             //            
             Console.ReadKey(true);
         }
     }
 }

좋은 웹페이지 즐겨찾기