手机
当前位置:查字典教程网 >编程开发 >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#编写获取远程IP,MAC的方法

C# 获取属性名的方法

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

C#图片压缩的实现方法

C#访问应用程序配置文件的方法

深入C#中使用SqlDbType.Xml类型参数的使用详解

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

精品推荐
分类导航