[c#]控制台进度条的示例
感觉很好玩,翻译成C#版。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace ConsoleProcessBar
{
class Program
{
static void Main(string[] args)
{
Boolean isBreak = false;
ConsoleColor colorBack = Console.BackgroundColor;
ConsoleColor colorFore = Console.ForegroundColor;
//(0,0)(Left,Top) 第一行
Console.WriteLine("***********TE Mason*************");
Console.BackgroundColor = ConsoleColor.DarkCyan;
for (int i = 0; i < Console.WindowWidth - 3; i++)
{
//(0,1) 第二行
Console.Write(" ");
}
//(0,1) 第二行
Console.WriteLine(" ");
Console.BackgroundColor = colorBack;
//'(0,2) 第三行
Console.WriteLine("0%");
// '(0,3) 第四行
Console.WriteLine("<按【Enter】键停止>");
for (int i = 0; i <= 100; i++)
{
if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Enter)
{
isBreak = true;
break;
}
Console.BackgroundColor = ConsoleColor.Yellow;
// '/返回完整的商,包括余数,SetCursorPosition会自动四舍五入
Console.SetCursorPosition(i * (Console.WindowWidth - 2) / 100, 1);
// 'MsgBox(i * (Console.WindowWidth - 2) / 100);
// 'MsgBox(Console.CursorLeft);
//'MsgBox(Console.CursorSize);
Console.Write(" ");
Console.BackgroundColor = colorBack;
Console.ForegroundColor = ConsoleColor.Green;
Console.SetCursorPosition(0, 2);
Console.Write("{0}%", i);
Console.ForegroundColor = colorFore;
Thread.Sleep(500);
}
Console.SetCursorPosition(0, 3);
Console.Write(isBreak ? "停止!!!" : "完成");
Console.WriteLine(" ");
Console.ReadKey();
Console.ReadKey(true);
}
}
}

[c#]控制台进度条的示例的更多相关文章
- [vb.net]控制台进度条的示例
Private Sub ConsoleProcessBar() Dim isBreak As Boolean = False Dim colorBack As ConsoleColor = Conso ...
- 用C#实现控制台进度条
在写一些简单的控制台测试程序时,经常希望能够在程序运行的过程中实现进度条的功能以便查看程序运行的速度或者进度.本文以C#为例,实现简单的控制台进度条,以供大家参考(本文底部附下载地址). 1.实现效果 ...
- Python 控制台进度条的实现
进行爬虫等耗时的任务时,有时会想在控制台输出进度条,以显示当前任务进度.这里总结了两种方法. 方法1:使用tqdm模块 示例代码: from time import sleep from tqdm i ...
- Python中如何写控制台进度条的整理
本文实例讲述了Python显示进度条的方法,是Python程序设计中非常实用的技巧.分享给大家供大家参考.具体方法如下: 首先,进度条和一般的print区别在哪里呢? 答案就是print会输出一个\n ...
- ruby 编写控制台进度条
ruby 中,$stdout.flush 让控制台当前行内容可以重写,以此我们可以做出进度条的效果. def set_progress(index, char = '*') print (char * ...
- php+javascript实现的动态显示服务器运行程序进度条功能示例
本文实例讲述了php+javascript实现的动态显示服务器运行程序进度条功能.分享给大家供大家参考,具体如下: 经常有这样的业务要处理,服务器上有较多的业务需要处理,需要分批操作,于是就需要一个提 ...
- C#控制台进度条(Programming Progress bar in C# Consle application)
以下代码从Stack Overflow,觉得以后会用到就收藏一下,我是辛勤的搬运工,咿呀咿呀哟- 1.showing percentage in .net console application(在. ...
- Bootstrap 警告、进度条、列表组、面板
摘要:该部分包括警告.进度条.列表组.面板等部分. 1.警告(alert) 1.1 基本的警告(.alert) 警告的基类是 .alert .和其他样式类一块使用.例如: .alert-success ...
- 微信小程序组件解读和分析:六、progress进度条
progress进度条组件说明: 进度条,就是表示事情当前完成到什么地步了,可以让用户视觉上感知事情的执行.progress进度条是微信小程序的组件,和HTML5的进度条progress类似. pro ...
随机推荐
- ASP.NET页面传值与跳转
asp.net页面传值的五种方法:QueryString,Session,Application,Request.Cookies,Server.Transfer 其中Cookie和Server.Tra ...
- HTML5 初始文档声明
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- PHPCMS 标签与解析小记_Jason
Content模块下的标签解析:phpcms\modules\content\classes\content_tag.class.php 推荐位:public function position
- OpenStack点滴03-Neutron
OpenStack Neutron是一个比较复杂的组件,如果说OpenStack安装部署过程哪一个组件最麻烦,那就肯定是网络组件Neutron了. 因为我对OpenStack网络这块也不是很熟,就把我 ...
- Mongodb增加权限管理
前言: 随着列式存储理念的成熟,越来越多的开发者开始接纳mongodb,hbase这类大储存的分布式列式数据库.特别是mongodb的这种快速搭建,快速使用特点,使其得到更多人的青睐.本人主要通过官 ...
- Java was started but returned exit code=13
安装Eclipse(32位)后打开报错:Java was started but returned exit code=13 解决方法: 1,首先我查看了我当前安装的JDK版本,发现是64位的: 2, ...
- 在线安装maven插件问题:Cannot complete the install because one or more required items could not be found.
用Eclipse在线安装的方式:Help-->Install New Software 地址输入:http://m2eclipse.sonatype.org/sites/m2e/,列表中打勾勾 ...
- owncloud乱码问题
没有人回答那我就献丑了,废话有点多,请跳着看. 先说结论:最后我选择了 Seafile 我去年之前用box同步个人文件,前几个月的时候吧,发现box不能上传几百M的文件,我才知道之前为什么会丢文件了… ...
- 虚拟机LUN扩大后,重新分区
[root@ywcrmdb ~]# fdisk -l Disk /dev/sda: 751.6 GB, 751619276800 bytes 255 heads, 63 sectors/track, ...
- typedef与define的区别
1) #define是预处理指令,在编译预处理时进行简单的替换,不作正确性检查,不关含义是否正确照样带入,只有在编译已被展开的源程序时才会发现可能的错误并报错.例如:#define PI 3.1415 ...