0

まず、次のすべてのコントロールをフラット化する機能がありますControl

Protected Function GetAllControls(Optional ownerControl As Control = Nothing) As IEnumerable(Of Control)

    Dim ret = New List(Of Control)()
    For Each child As Control In If(ownerControl, Me).Controls
        ret.AddRange(GetAllControls(child))
    Next
    ret.Add(ownerControl)
    Return ret

End Function

次に、このコードを使用してコントロールの特定のボタンを非表示にします。

Dim buttons = GetAllControls().Where(Function(c) c.Name.StartsWith("subButton"))
For Each ctrl As Control In buttons
    ctrl.Visible = False
    Debug.WriteLine("Hid button " & ctrl.Name)
Next

それでも、4 つのボタン (正しい数) が非表示になったNullReferenceException後、VS2012 でラムダ式が強調表示された が表示されます。

何が原因でしょうか?

4

1 に答える 1