手机
当前位置:查字典教程网 >编程开发 >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#中常使用进度条的代码

C# 读取指定路径配置文件的方法

C#使用非托管代码直接修改字符串的方法

配置C#的系统环境变量的方法

C#中使用IrisSkin2.dll美化WinForm程序界面的方法

C# 获取打印机当前状态的方法

C#删除文件目录或文件的解决方法

C# 无边框窗体边框阴影效果的简单实现

c#中分割字符串的几种方法

C#中如何执行存储过程方法

精品推荐
分类导航