简体   繁体   English

设置所有打开表格的位置

[英]set the location of all open forms

this code lets me set the location of the form each time I drag my map. 此代码使我每次拖动地图时都可以设置form的位置。

Private Sub map_OnMapDrag() Handles map.OnMapDrag
    If f2c1.Visible Then
        f2c1.Location = camera1.LocalPosition + New Point(20, -240)
    End If
    If f2c2.Visible Then
        f2c2.Location = camera2.LocalPosition + New Point(20, -240)
    End If
    If f2c3.Visible Then
        f2c3.Location = camera3.LocalPosition + New Point(20, -240)
    End If
End Sub

however, I want it on a public sub.. 但是,我希望在公共子上使用它。

and this code, which I think gets all the visible forms .. 和这段代码,我认为它可以获得所有 可见的 forms ..

Dim forms = Application.OpenForms.OfType(Of frmCamera)()
    While forms.Count > 0
        forms(forms.Count - 1).Visible = True
    End While

how can I make it so that all visible forms gets their location everytime I drag it, so that even if I dynamically added another form it won't be a problem. 我怎样才能做到这一点,以便每次拖动它时所有可见的表单都可以得到它们的位置,因此即使我动态添加了另一form也不会出现问题。 that's my goal. 那是我的目标。

can you guys fix this for me.. 你们能帮我解决这个问题吗?

Dim forms = Application.OpenForms.OfType(Of frmCamera)()
    While forms.Count > 0
        forms(forms.Count - 1).Visible = True
    End While
    forms.Location = 'location that I want

Try this: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM