:'( hi guys hope you can help
i have written a small project used to simulate a cash reg however i have 3 froms on it ,main,checkout and about my problem is that if i move my main form to say left had of screen when i click on checkout or about those forms open in there orginal posisition what i need to know is there anyway of locking these forms to the main form so as nomatter where the main form is on screen the other forms will open on top of it

hope you understand what i m trying to do

thankyou
stephen

Dani AI

Generated

A few practical, low-friction options for 's cash-register forms (main, checkout, about). was right that MDI is one route, but for a small app it is often simpler to make the secondary windows "owned" by the main form and keep their positions in sync, or to host the screens inside the main form (panels/usercontrols) to avoid multiple windows entirely.

To keep separate windows tied to the main form without MDI:

  • Give the child form an owner and set its StartPosition so you control placement.
  • Store a per-form offset (for example in Tag) when you show it.
  • Handle the main form's move/location-changed event and reposition owned forms using those offsets.

Example (VB.NET):

' from MainForm, when showing the child
Dim checkout As New CheckoutForm()
checkout.Owner = Me
checkout.StartPosition = FormStartPosition.Manual
checkout.Tag = New Point(24, 24)    ' offset from main form
checkout.Location = New Point(Me.Left + 24, Me.Top + 24)
checkout.Show()
' keep owned forms in place as the main form moves
Private Sub MainForm_LocationChanged(sender As Object, e As EventArgs) Handles Me.LocationChanged
    For Each f As Form In Me.OwnedForms
        If TypeOf f.Tag Is Point Then
            Dim off As Point = CType(f.Tag, Point)
            f.Location = New Point(Me.Left + off.X, Me.Top + off.Y)
        End If
    Next
End Sub

Notes and small tips:

  • Owned forms stay above the owner and minimize with it; see the Form.Owner and Form.OwnedForms docs for details (Form.Owner, Form.OwnedForms).
  • Set StartPosition to Manual (or use CenterParent with ShowDialog) so Windows does not pick the location for you (Form.StartPosition).
  • Use LocationChanged or Move to catch user-driven moves (LocationChanged).
  • For very small apps, showing/hiding panels or usercontrols inside one form avoids multi-window positioning headaches.

Recommended Answers

All 2 Replies

You could use the multiple-document interface (MDI) in which the forms are a "child" of the "parent" main form, but MDI program can be a pain. Why can't you just use the main form's properties to decide where the other forms should appear? For example, in the Form_Load event of Checkout...

Top = Form1.Top 'add any offset you want
Left = Form1.Left 'again add the desired offset

thanks for your help i can work with this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.