复选框多选

Checklistbox Multiple Selection

我一直在开发一个使用 Checkedlistbox 的应用程序,这样我就可以允许用户 select 多个框。

    Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
    For Each item As Object In Me.CheckedListBox1.CheckedItems
        Dim text As String = Me.CheckedListBox1.GetItemText(item)
    Next

    If text = "Line 1" Then
        CreateLine1()
    End If

    If text = "Line 2" Then
        CreateLine2()
    End If

    If text = "Line 3" Then
        CreateLine3()
    End If

    If Text = "Line 4" Then
        CreateLine4()
    End If

    If Text = "Line 5" Then
        CreateLine5()
    End If

一直到 "Line 10"。当应用程序运行时,它使用 cmd.exe 连接到 telnet 并发送命令。如果我有第 1 行和第 2 行 selected 第 1 行没有问题,但是当第 2 行运行时它会打开一个 cmd,几秒钟后什么也没有,打开另一个 cmd,并在未连接到的情况下仅运行命令远程登录。还有几个寡妇打开后记,四个或第五个 window 连接到 telnet。

如果在运行 telnet 后 select 编辑了一行,那么在转到下一行之前将那行分隔为 "Has been ran" 以避免我的问题。

补充信息: 这个应用程序有一个 select-all 和 deselect-all 按钮,所以我不能有任何会干扰它们的东西。

我已经尝试使用 socket 来替换 cmd.exe.....它并不顺利,我会继续下去。

除了 IP 地址和一些命令外,每个子行基本相同。

我希望你发布的原始代码不是你正在使用的......它看起来不太正确。

也许这样的东西更有用:

Imports System.Reflection
Public Class Form1

    Private Methods As New List(Of MethodInfo)

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim MI As MethodInfo
        For i As Integer = 1 To 10
            mi = Me.GetType.GetMethod("CreateLine" & i, Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Public)
            If Not IsNothing(MI) Then
                Methods.Add(MI)
            End If
        Next
    End Sub

    Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
        For Each Index As Integer In Me.CheckedListBox1.CheckedIndices
            Methods(Index).Invoke(Me, Nothing)
        Next
    End Sub

    Private Sub CreateLine1()
        Debug.Print("CreateLine1()")
    End Sub

    Private Sub CreateLine2()
        Debug.Print("CreateLine2()")
    End Sub

    Private Sub CreateLine3()
        Debug.Print("CreateLine3()")
    End Sub

    Private Sub CreateLine4()
        Debug.Print("CreateLine4()")
    End Sub

    Private Sub CreateLine5()
        Debug.Print("CreateLine5()")
    End Sub

    Private Sub CreateLine6()
        Debug.Print("CreateLine6()")
    End Sub

    Private Sub CreateLine7()
        Debug.Print("CreateLine7()")
    End Sub

    Private Sub CreateLine8()
        Debug.Print("CreateLine8()")
    End Sub

    Private Sub CreateLine9()
        Debug.Print("CreateLine9()")
    End Sub

    Private Sub CreateLine10()
        Debug.Print("CreateLine10()")
    End Sub

End Class

还有很多其他方法可以做到这一点...