vb.net - 有什么办法可以缩短这段代码吗?

标签 vb.net text progress-bar countdown

这是我想要缩短的代码,它使用一个进度条和一个与之一起倒数的标签:我正在使用 VB 语言

 If ProgressBar1.Value = 33 And Label2.Text = "Now:  Hold down power button (3 seconds)" Then
            Label2.Text = "Now:  Hold down power button (2 seconds)"
        End If

        If ProgressBar1.Value = 66 And Label2.Text = "Now:  Hold down power button (2 seconds)" Then
            Label2.Text = "Now:  Hold down power button (1 seconds)"
        End If

        If ProgressBar1.Value = 99 And Label2.Text = "Now:  Hold down power button (1 seconds)" Then
            Label2.Text = "Now:  Hold down power button (0 seconds)"
        End If

        If ProgressBar1.Value = 100 And Label2.Text = "Now:  Hold down power button (0 seconds)" Then
            Label2.Text = "Now:  Also hold down the home button (10 seconds)"
            Label2.Location = New Point(30, Label2.Location.Y)
            Label3.Text = "Next:  Release the power button only (15 seconds)"
            ProgressBar1.Value = 0
        End If

最佳答案

是的,有:

    Const BASE_MESSAGE As String = "Now:  Hold down power button ({0} seconds)"

    Select Case ProgressBar1.Value
       Case 33
          Label2.Text = String.Format(BASE_MESSAGE, 2)
       Case 66
          Label2.Text = String.Format(BASE_MESSAGE, 1)
       Case 99 
          Label2.Text = String.Format(BASE_MESSAGE, 0)

       Case 100
          Label2.Text = "Now:  Also hold down the home button (10 seconds)"
          Label2.Location = New Point(30, Label2.Location.Y)
          Label3.Text = "Next:  Release the power button only (15 seconds)"
          ProgressBar1.Value = 0

    End Select

关于vb.net - 有什么办法可以缩短这段代码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8582640/

相关文章:

c - 使用 GLUT 和 C 编写文本

c - 使用线程实现进度控制

progress-bar - 复制成功后,两个CouchDB数据库是否保证具有相同的序列号?

vb.net - 以编程方式设置 Crystal Report 的自定义纸张尺寸

c# - 如何制定标准(C# 与 VB.NET)

c - 使用C从txt文件中获取具体数据

java - 按下后退时将进度条重置为 0

mysql - 如何从另一台电脑连接Mysql数据库?

mysql - 使用 Sql 语法按日期过滤数据

c++ - 从 C++ 中的文本框中复制文本