如何分离可见表单实例的位置 [英] how to separate visible form instances' locations

查看:15
本文介绍了如何分离可见表单实例的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自这里的问题:问题

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

UPDATE 上面的代码获取所有可见的 forms 但由于它是通用的,所有可见的 forms 都出现在一个地方..

UPDATE the above code gets all visible forms but since its generic, all the visible forms appear on one place..

比方说,我有 3 个标记......名为 camera1 camera2 camera3..
Form_Load 上,我将点击这 3 个标记,然后会出现一个假定的视频源(在本例中,每个都有一个 form2 的新实例)

let's say, I have 3 markers.. named camera1 camera2 camera3..
on Form_Load I will click those 3 markers, and a supposed video feed will appear (in this case, each with a new instance of form2)

这是我的代码,它可以满足我的要求,唯一的问题是,我希望它可以在未来动态添加更多而不是预定义的情况下重复使用.

this is my code in which does what I want, only problem is, I want it to be reusable for the future of dynamically adding more rather than this, predefined.

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 与他们同在.

我希望它在一个 functionsub 上可以做到这一点..

I want it on a function or sub that will do this..

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

有什么需要可以问我..谢谢

ask me if you need anything.. thanks

推荐答案

我做了一些解决方案

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

这仍然不是我心中的理想选择,但这实际上暂时回答了我的问题.

this is still not the ideal thing that is on my mind, but this practically answers my question for the moment.

这篇关于如何分离可见表单实例的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆