源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C# cmd中修改显示(显示进度变化效果)的方法

  • 时间:2022-08-07 08:12 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C# cmd中修改显示(显示进度变化效果)的方法
[u]复制代码[/u] 代码如下:
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”也能达到目的,表示将光标回到当前第一行,如下:
[u]复制代码[/u] 代码如下:
public void PrintPercentage(int FinishedCount, int TotalCount)  {         decimal finishedPercentage = Convert.ToDecimal(FinishedCount) / Convert.ToDecimal(TotalCount);         Console.WriteLine("\r" + (finishedPercentage * 100).ToString("f1") + "%");  } 
相比之下前一种更加灵活一点,可以定位到任何位置
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部