使 form1 上的所有文本框和组框中的所有文本框不可见

问题描述 投票:0回答:1

您好,尝试使 form1 上选定的文本框和 groupboxs1 内的文本框不可见

我有8个文本框,form1上有1到4,groupbox1中有文本框5到8也在form1上 我希望通过单击按钮使文本框 3、4、5 和 6 不可见 以下代码仅使文本框 3 和 4 不可见,而文本框 5 和 6 可见

   For i = 3 To 6
            Dim c As String = "ComboBox" & i.ToString
            DirectCast(Me.Controls.Find(c, False)(0), ComboBox).Visible = False
        Next



i found this code that works but will only make "ALL" the textboxes inside the groupbox1 invisible but not the textboxes on form1


 Dim Ctl As Control
        For Each Ctl In Controls
            If TypeOf Ctl Is GroupBox Then
                Dim Ctl1 As Control
                For Each Ctl1 In Ctl.Controls
                    If TypeOf Ctl1 Is TextBox Then
                        Ctl1.Visible = True
                    End If
                Next
            End If
        Next

谢谢格雷格

vb.net textbox visual-studio-2019 invisible groupbox
1个回答
0
投票

谢谢 jmcilhinney,我知道我放置了 1 到 8 个文本框,但我正在处理超过 130 个文本框,并且我使用的代码效果很好。

 For i = 3 To 6
        Dim c As String = "textBox" & i.ToString
        DirectCast(Me.Controls.Find(c, False)(0), textBox).Visible = False
    Next

(是的,我在第一条消息中确实有组合框,我复制了错误的代码) 上面的代码怎么不会做任何文本框

现在我可以使用以下代码来帮助任何人

  For i = 46 To 78
        Dim c As String = "textbox" & i.ToString
        DirectCast(GroupBox1.Controls.Find(c, False)(0), TextBox).Visible = False
    Next
© www.soinside.com 2019 - 2024. All rights reserved.