找已選取的CheckBox (VB.NET)

找已選取的CheckBox (VB.NET)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim MSGSTRING As String = "你的興趣為:" & vbCrLf
        Dim OBJCHECKBOX As CheckBox

        For Each CHKBOX As Object In Me.Controls
            If CHKBOX.GetType.ToString() = "System.Windows.Forms.CheckBox" Then
                OBJCHECKBOX = CType(CHKBOX, CheckBox)

                If OBJCHECKBOX.Checked Then
                    MSGSTRING = MSGSTRING + CHKBOX.TEXT + vbCrLf
                End If

            End If
        Next
        MsgBox(MSGSTRING)

    End Sub


如有錯誤 歡迎指正