如何分隔可见表单实例的位置

时间:2013-12-05 06:49:55

标签: vb.net winforms

来自这里的问题:Question

Dim forms As Collections.Generic.IEnumerable(Of frmMain) = Application.OpenForms.OfType(Of frmMain).Where(Function(frm) frm.Visible)

For Each f As Form In forms
f.Location = New Point(0, 0) ' set coordinate as needed
Next

更新以上代码全部显示forms但由于其通用,所有可见的forms都出现在一个地方..

比方说,我有3个标记..名为camera1 camera2 camera3 ..
Form_Load上我会点击这3个标记,并会显示一个假定的视频Feed(在这种情况下,每个都有一个form2的新实例)

这是我的代码,其中包含了我想要的,唯一的问题是,我希望它可以重复使用,以便动态添加更多而不是预定义的。

Dim f2c1 As New Form2
Dim f2c2 As New Form2
Dim f2c3 As New Form2
    If f2c1.Visible = True Then
        f2c1.Location = camera1.LocalPosition + New Point(20, -240)
    End If
    If f2c2.Visible = True Then
        f2c2.Location = camera2.LocalPosition + New Point(20, -240)
    End If
    If f2c3.Visible = True Then
        f2c3.Location = camera3.LocalPosition + New Point(20, -240)
    End If



那个代码就是这个..如果我点击标记,拖动地图。视频供稿form2与他们保持联系。

enter image description here

我希望functionsub能够做到这一点。

'Public Sub when I drag the map()
'every form visible
'will follow -- let's say, will follow what marker clicked them

问我是否需要任何东西..谢谢

1 个答案:

答案 0 :(得分:0)

我做了一些解决方法

Dim mList As New List(Of String)



marker.ToolTipMode = MarkerTooltipMode.Always   'as an indetifier of each markers as
marker.ToolTipText = dtrow("MarkerName")        'I have added it to a for each

Try

        For Each m In mList                     'get items from the list
            If item.ToolTipText = m Then        'check same name
                Dim f As New Form2
                With f
                    If .Visible = True Then
                        .Hide()
                    Else
                        .Show()
                        Dim p As New Point
                        p = item.LocalPosition + New Point(20, -240)
                        .Location = p              'after I click form will appear right next to them
                        .Text = m
                    End If
                End With
                Exit Sub
            End If
        Next

    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

这仍然不是我心目中的理想事情,但这实际上回答了我的问题。