0

嘿伙计们,我动态创建了一些复选框,现在我想将它们的值设置为 False。我的问题是我无法访问它们,因为没有说明名称。

我这样创建它们:

        For j = 0 To column - 1

        For i = 0 To row - 1
            MyCheckboxes(counter) = New CheckBox
            MyCheckboxes(counter).Visible = True
            MyCheckboxes(counter).Checked = True
            MyCheckboxes(counter).Text = ""
            MyCheckboxes(counter).Size = New Size(15, 14)
            MyCheckboxes(counter).Name = "Check" + counter.ToString
            Me.Controls.Add(MyCheckboxes(counter))
            MyCheckboxes(counter).Location = New Point(Xpos, Ypos)
            Xpos = Xpos + 20
            counter = counter + 1
        Next i
        Ypos = Ypos + 20
        Xpos = 160
    Next j

进入一个全局数组

   Public MyCheckboxes() As System.Windows.Forms.CheckBox

现在我想在单击事件的按钮中将值设置为 False:

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    Dim i As Integer = 0


    Me.Controls("Check" & i).Checked = False 'Here it says: Checked is not a Member of 'System.Windows.Forms.Control'
    CheckBox0.Checked = False ' Here it says CheckBox0 is not declared. It may be inaccessible due to its protection level.


End Sub

我不知道我做错了什么我搜索了近3个小时的原因。请帮我干杯

4

1 回答 1

0

只需通过您的阵列访问它们。

MyCheckboxes(i).Checked = False
于 2012-05-05T23:26:40.500 回答