基本信息
源码名称:控制台 ProgressBar进度条
源码大小:0.02M
文件格式:.zip
开发语言:C#
更新时间:2020-04-24
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
ProgressBar进度条


 string filepath = @"E:\Adobe Photoshop CS6.zip";
            string filename = Path.GetFileName(filepath);
            Console.WriteLine("Start Reading : {0}", filename);
            FileStream fs = new FileStream(filepath, FileMode.Open);  //open file 
            long count = fs.Length;//文件长度  
            int start = 0;//开始读取
            int num = 0; //每次读取的长度
            long end = count;//剩余读取长度
            double prePercent = 0;
            ConsoleColor colorBack = Console.BackgroundColor;
            ConsoleColor colorFore = Console.ForegroundColor;
            if (count > 0)
            {
                //绘制读条背景界面
                Console.WriteLine("********************* Loading *********************");
                Console.BackgroundColor = ConsoleColor.DarkCyan;
                for (int i = 0; i <= 50; )
                {
                    Console.Write(" ");
                }
                Console.WriteLine(" ");
                Console.BackgroundColor = colorBack;
                Console.WriteLine("0%");
                Console.WriteLine("***************************************************");
            }
            byte[] bytes = new byte[1024*10];
            int maxlength = bytes.Length;
            while (end > 0)
            {
                fs.Position = start;
                num = 0;
                if (end < maxlength)
                    num = fs.Read(bytes, 0, Convert.ToInt32(end));
                else
                    num = fs.Read(bytes, 0, maxlength);
                if (num == 0)
                    break;
                start = num;
                end -= num;
                double percent;
                if (start <= count)
                {
                    percent = (double)start / count;
                    percent = Math.Ceiling(percent * 100);
                }else
                {
                    percent = 1;
                    percent = Math.Ceiling(percent * 100);
                }
                for (int i = Convert.ToInt32(prePercent); i <= percent; i )
                {
                    //绘制进度条进度                 
                    Console.BackgroundColor = ConsoleColor.Yellow;//设置进度条颜色                
                    Console.SetCursorPosition(i/2, 2);//设置光标位置,参数为第几列和第几行                
                    Console.Write(" ");//移动进度条                
                    Console.BackgroundColor = colorBack;//恢复输出颜色                
                    //更新进度百分比,原理同上.                
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.SetCursorPosition(0, 3);
                    Console.Write("{0}%   ", i);
                    Console.ForegroundColor = colorFore;
                }
                prePercent = percent;
            }
            fs.Close();
            Console.WriteLine(" Finished Reading !");
            Console.ReadLine();