Public Class Form1
Private Function AllEnabled(ByVal b As Boolean) As Boolean
For i As Integer = 0 To 2
Dim c As CheckBox = CType(Me.Controls("CheckBox" & i.ToString), CheckBox)
c.Enabled = b
Next
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Call AllEnabled(False)
End Sub
End Class
在c.Enabled = b
处高亮显示出现错误(Object reference not set to an instance of an object.)
但是当我使用checkbox1.enabled = b
代替c.enabled = b
时,运行正常。
所以我认为问题不在于b
,对吗?
& 我该如何解决这个问题?