手机
当前位置:查字典教程网 >编程开发 >C#教程 >C# cmd中修改显示(显示进度变化效果)的方法
C# cmd中修改显示(显示进度变化效果)的方法
摘要:复制代码代码如下:publicvoidPrintPercentage(intFinishedCount,intTotalCount){dec...

复制代码 代码如下:

public void PrintPercentage(int FinishedCount, int TotalCount)

{

decimal finishedPercentage = Convert.ToDecimal(FinishedCount) / Convert.ToDecimal(TotalCount);

Console.SetCursorPosition(0, Console.CursorTop - 1);

Console.WriteLine((finishedPercentage * 100).ToString("f1") + "%");

}

其中SetCursorPosition的目的就是重置光标到,里面参数的含义是(left, top),当前cmd最下面一行即为top.ToString("f1")是指保留一位小数.

或者用“r”也能达到目的,表示将光标回到当前第一行,如下:

复制代码 代码如下:

public void PrintPercentage(int FinishedCount, int TotalCount)

{

decimal finishedPercentage = Convert.ToDecimal(FinishedCount) / Convert.ToDecimal(TotalCount);

Console.WriteLine("r" + (finishedPercentage * 100).ToString("f1") + "%");

}

相比之下前一种更加灵活一点,可以定位到任何位置

【C# cmd中修改显示(显示进度变化效果)的方法】相关文章:

C#控制台输出进度和百分比的实例代码

在Winform动态启动、控制台命令行的方法

C# 运用params修饰符来实现变长参数传递的方法

用C#编写获取远程IP,MAC的方法

基于反射解决类复制的实现方法

C#中一些你可能没用过的调试窗口的方法

C#中判断本地系统的网络连接状态的方法

使用Deflate算法对文件进行压缩与解压缩的方法详解

C#中读写INI文件的方法例子

C# DropDownList中点击打开新窗口的方法

精品推荐
分类导航