手机
当前位置:查字典教程网 >编程开发 >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#处理JPEG头信息的方法

C# 获取属性名的方法

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

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

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

C# 如何判断两个文件内容是否相同的方法

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

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

精品推荐
分类导航