I have a problem with alignment of the child form in a parent form.
I would like to have this Form3 in the upper right corner of the Form1 - always - even when user changes the size of the form1. Form3 it has to be located there. The location property can only align it by upper left corner, so this isnt much helpful.

I mean something like "Anchor" property for tools, where you can set all 4 sides. But for forms this is impossible.

Any ideas how to do it?

Dani AI

Generated

Since asked if this is MDI: yes — MDI child coordinates are relative to the MdiClient control that hosts children, not the parent Form's chrome. The reliable way is to reposition the child when the MdiClient size changes (or when the child is created/activated). Compute X as (mdiClient.ClientSize.Width - child.Width) and clamp to zero so the child never goes off the left edge.

Here is a compact pattern to use in the MDI parent: find the MdiClient, wire its SizeChanged and the parent MdiChildActivate events, and move the specific child (Form3) when needed.

private MdiClient GetMdiClient()
{
    foreach (Control c in this.Controls)
        if (c is MdiClient) return (MdiClient)c;
    return null;
}

private void PositionForm3UpperRight()
{
    Form f = null;
    foreach (Form ch in this.MdiChildren)
        if (ch.Name == "Form3") { f = ch; break; } // or use 'is Form3'
    if (f == null || f.IsDisposed || f.WindowState != FormWindowState.Normal) return;

    var client = GetMdiClient();
    if (client == null) return;
    int x = Math.Max(0, client.ClientSize.Width - f.Width);
    f.Location = new Point(x, 0);
}

Call PositionForm3UpperRight() from the MdiClient.SizeChanged handler and from MdiChildActivate (and after you Show the child). Notes: skip repositioning if the child is maximized or minimized, clamp X to avoid negative values (MDI will otherwise show scrollbars), and use MdiClient rather than the parent form ClientSize to account for menus/toolbars. As pointed out, if this sort of manual positioning feels brittle, consider a non‑MDI layout (docking/panels) which can simplify fixed placement.

Recommended Answers

All 3 Replies

Are you referring to MDI forms or is one form on top of another?

Yes, to MDI

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.