vb.net计算标签文本

时间:2018-03-24 10:07:04

标签: vb.net count label

好吧,我非常依赖计算我得到的标签数量(已启用)。

我有10个标签,默认文字显示“已启用”,但也有按钮将文字更改为“已停用”

所以我想计算一下10个中有多少个启用按钮。

7/10或5/10或1/10等...

试过:

Dim Number1 As Double
Dim Number2 As Double
Dim Number3 As Double
Dim result As Double

 If Label100.Text = "Enabled" Then
            num1.Text = "1"
        ElseIf Label100.Text = "Disabled" Then
            num1.Text = "0"
        End If
        Number1 = num1.Text
        Number2 = num2.Text
        Number3 = num3.Text
        result = Number1 + Number2 + Number3
        StatsCount.Text = result

我在启用/禁用标签旁边制作了标签,如果已启用则为1,如果为已禁用,则为0,但也不起作用。

2 个答案:

答案 0 :(得分:0)

除非您正在为视障人士创建应用,否则我不会看到标签的重点。按钮是"灰色"禁用时,你已经有了视觉线索。计算循环控制按钮并查看其启用的属性。

Private Sub HowManyEnabled()
        Dim Count As Integer = 0
        For Each ctr As Control In Controls
            If TypeOf ctr Is Button Then
                If CType(ctr, Button).Enabled Then
                    Count += 1
                End If
            End If
        Next
        Debug.Print($"There are {Count} enabled buttons")
End Sub

如果您没有使用最新的vb,那么

Debug.Print(String.Format("There are {0} enabled buttons", Count))

答案 1 :(得分:0)

所以你想要计算标签。行

Private Sub HowManyEnabled()
        Dim Count As Integer = 0
        For Each ctr As Control In Controls
            If TypeOf ctr Is Label Then
                If CType(ctr, Label).Text = "Enabled" Then
                    Count += 1
                End If
            End If
        Next
        Debug.Print($"There are {Count} enabled labels")
End Sub