遍历控件 vb.net 2005

来源:互联网 发布:下载打扑克软件 编辑:程序博客网 时间:2024/05/21 07:27

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Cont As Control
        Dim i as integer
        txtbox1.Text = "txt1"
        txtbox2.Text = "txt2"

        'Controls(0).Text = "Hello"
        Controls.Item(0).Text = "Hello"
        For i = 0 To Controls.Count - 1
            Debug.WriteLine(Controls(i).GetType)

            'Me.Controls(ii).GetType.Name()
        Next

        i = 0
        Dim T As Object
        For Each Cont In Me.Controls

            Select Case Cont.GetType.Name
                Case "CheckBox"
                    MsgBox("is checkbox")
                Case "TextBox"
                    MsgBox("is textbox")
                Case "Label"
                    MsgBox("Label")
                Case "Button"
                    MsgBox("is Button")
            End Select

            i += 1
            If TypeOf Cont Is TextBox Then
                MessageBox.Show("The control is a textbox." & _
                       " Control:" & i & vbCrLf & Cont.Text)
            ElseIf TypeOf Cont Is Button Then
                MsgBox("The control is a button." & " Control:" & i)
            ElseIf TypeOf Cont Is CheckBox Then
                MsgBox("The control is a checkbox." & " Control:" & i)
            ElseIf TypeOf Cont Is Label Then
                MsgBox("The control is a Label." & " Control:" & i)

            End If
          
        Next Cont
    End Sub

原创粉丝点击