【问题标题】:Form doesn't do what I intend him to表格并没有按照我的意愿去做
【发布时间】:2014-02-10 18:48:45
【问题描述】:

这是我的工作代码 - 每次单击标记时,它都会显示其持有的相应表单。 代码 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

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

我错过了什么/做错了什么?如果您需要什么,请告诉我。
更新:似乎word() 没有注册 3。我点击它,它的值是 1。

【问题讨论】:

    标签: .net vb.net winforms foreach


    【解决方案1】:

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

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

    到:

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

    【讨论】:

      【解决方案2】:
      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
      

      【讨论】:

        猜你喜欢
        • 2023-03-04
        • 2021-12-29
        • 1970-01-01
        • 2021-02-26
        • 2021-12-02
        • 1970-01-01
        • 1970-01-01
        • 2021-08-16
        • 2018-09-09
        相关资源
        最近更新 更多