简体   繁体   中英

set the location of all open forms

this code lets me set the location of the form each time I drag my map.

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 ..

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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