AdorableVB
AdorableVB

Reputation: 1393

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

Upvotes: 0

Views: 113

Answers (1)

Adventure
Adventure

Reputation: 189

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

Upvotes: 1

Related Questions