首页 > 学院 > 开发设计 > 正文

[vb.net]控制台进度条的示例

2019-11-14 15:54:13
字体:
来源:转载
供稿:网友
 1  PRivate Sub ConsoleProcessBar() 2         Dim isBreak As Boolean = False 3         Dim colorBack As ConsoleColor = Console.BackgroundColor 4         Dim colorFore As ConsoleColor = Console.ForegroundColor 5         '(0,0)(Left,Top) 第一行 6         Console.WriteLine("***********TE Mason*************") 7         Console.BackgroundColor = ConsoleColor.DarkCyan 8         For i = 0 To Console.WindowWidth - 3 9             '(0,1) 第二行10             Console.Write(" ")11         Next12         '(0,1) 第二行13         Console.WriteLine(" ")14         Console.BackgroundColor = colorBack15         '(0,2) 第三行16         Console.WriteLine("0%")17         '(0,3) 第四行18         Console.WriteLine("<Press Enter To Break>")19 20         For i = 0 To 10021             If Console.KeyAvailable AndAlso Console.ReadKey(True).Key = ConsoleKey.Enter Then22                 isBreak = True23                 Exit For24             End If25             Console.BackgroundColor = ConsoleColor.Yellow26             '/返回完整的商,包括余数,SetCursorPosition会自动四舍五入27             Console.SetCursorPosition(i * (Console.WindowWidth - 2) / 100, 1)28             'MsgBox(i * (Console.WindowWidth - 2) / 100)29             'MsgBox(Console.CursorLeft)30             'MsgBox(Console.CursorSize)31             Console.Write(" ")32             Console.BackgroundColor = colorBack33             Console.ForegroundColor = ConsoleColor.Green34             Console.SetCursorPosition(0, 2)35             Console.Write("{0}%", i)36             Console.ForegroundColor = colorFore37             Threading.Thread.Sleep(1000)38         Next39 40         Console.SetCursorPosition(0, 3)41         Console.Write(IIf(isBreak, "Break!!!", "Finish"))42         Console.WriteLine("                           ")43         Console.ReadKey()44         Console.ReadKey(True)45     End Sub


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表