十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
這篇文章主要介紹“C#進(jìn)度條中怎么實(shí)現(xiàn)控制臺顯示”,在日常操作中,相信很多人在C#進(jìn)度條中怎么實(shí)現(xiàn)控制臺顯示問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”C#進(jìn)度條中怎么實(shí)現(xiàn)控制臺顯示”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
太和網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,太和網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為太和上1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的太和做網(wǎng)站的公司定做!
來看看實(shí)際的實(shí)現(xiàn):
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TextProgressing { { //C#進(jìn)度條之控制臺顯示static void Main(string[] args) { bool isBreak = false; ConsoleColor colorBack = Console.BackgroundColor; ConsoleColor colorFore = Console.ForegroundColor; //***行信息 Console.WriteLine("** jinjazz now working**"); //第二行繪制進(jìn)度條背景 Console.BackgroundColor = ConsoleColor.DarkCyan; for (int i = 0; ++i <= 25; ) { Console.Write(" "); } Console.WriteLine(" "); Console.BackgroundColor = colorBack; //第三行輸出進(jìn)度 Console.WriteLine("0%"); //第四行輸出提示,按下回車可以取消當(dāng)前進(jìn)度 Console.WriteLine(""); //上面繪制了一個完整的工作區(qū)域,下面開始工作 //開始控制進(jìn)度條和進(jìn)度變化 for (int i = 0; ++i <= 100; ) { //先檢查是否有按鍵請求,如果有,判斷是否為回車鍵,如果是則退出循環(huán) if ( //C#進(jìn)度條之控制臺顯示Console.KeyAvailable && System.Console.ReadKey(true).Key == ConsoleKey.Enter) { //C#進(jìn)度條之控制臺顯示isBreak = true; break; } //繪制進(jìn)度條進(jìn)度 Console.BackgroundColor = ConsoleColor.Yellow; //設(shè)置進(jìn)度條顏色 Console.SetCursorPosition(i / 4, 1); //設(shè)置光標(biāo)位置,參數(shù)為第幾列和第幾行 Console.Write(" ");//移動進(jìn)度條 Console.BackgroundColor = colorBack;//恢復(fù)輸出顏色 //更新進(jìn)度百分比,原理同上. Console.ForegroundColor = ConsoleColor.Green; Console.SetCursorPosition(0, 2); Console.Write("{0}%", i); Console.ForegroundColor = colorFore; //模擬實(shí)際工作中的延遲,否則進(jìn)度太快 System.Threading.Thread.Sleep(100); } //工作完成,根據(jù)實(shí)際情況輸出信息,而且清楚提示退出的信息 Console.SetCursorPosition(0, 3); Console.Write(isBreak ? "break!!!" : "finished."); Console.WriteLine(" "); //等待退出 Console.ReadKey(true); } } //C#進(jìn)度條之控制臺顯示 }
到此,關(guān)于“C#進(jìn)度條中怎么實(shí)現(xiàn)控制臺顯示”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!