表格不符合我的意图

时间:2014-01-21 09:12:55

标签: .net vb.net winforms foreach

这是我的工作代码 - 每次点击一个标记时,它都会显示其所持有的相应形式。 代码A

 For Each elem In aList
                If item.ToolTipText = elem.MarkerName Then

                    Dim camera = markerDtable.Select("MarkerName =" & " '" & elem.MarkerName & "'")(0)("cameraID")
                    Dim host = markerDtable.Select("MarkerName =" & " '" & elem.MarkerName & "'")(0)("HostAddress")       

                    With f
                        .Show()
                        .AxXHDec1.Camera = camera
                        .AxXHDec1.Host = host
                        .AxXHDec1.Play = 1
                        Dim p As New Point
                        p = item.LocalPosition + New Point(45, 68)
                        .Location = p
                        .Text = elem.MarkerName
                    End With
                    Exit Sub
                End If
            Next

这是我基于第二个的代码,相同的程序虽然不是标记,但是按钮。 代码B

For Each btn In bList
        Dim fcb As New Fcamera4Building
        Dim word() As String = btn.Name.Split("m"c)
        With fcb
            .Show()
            .AxXHDec1.Camera = word(1)
            .AxXHDec1.Host = 'get corresponding HostAddress depending on what buttonName'
            .AxXHDec1.Play = 1
            Dim p As New Point
            p = btn.Location + New Point(70, 160)
            .Location = p
        End With
        Exit Sub
    Next

我认为我做了我应该做的事情,但是,CODE B显示的是相同的形式。当我点击CAM1按钮时,我有两个按钮(从开始时加载的数据库),给我一个相机。但是当我点击CAM3同时显示相同的表单和相同的位置时。

我错过了什么/做错了什么?如果你需要什么,请告诉我 更新:似乎word()未注册3.请点击,其值为1.

2 个答案:

答案 0 :(得分:0)

如果您的相机名称是“CAM1”,“CAM2”,则可能值得更改:

Dim word() As String = btn.Name.Split("m"c)

到:

Dim word() As String = btn.Name.ToLower.Split("m"c)

答案 1 :(得分:0)

Private Sub nBtn_Click(ByVal sender As Button, ByVal e As System.EventArgs)
    For Each btn In b2List
        If sender.Text = btn Then ' This will check the same name so it will distinguish which form will be shown.
            ' do code