Fix managed TitleBar affecting Control placement#117
Conversation
…ngle by title bar height When using a managed TitleBar, the title bar area was considered part of the client area, causing controls placed at (0, 0) to appear under the title bar. Changes: - ControlAdapter: Override DisplayRectangle to offset by visible title bar height - ControlAdapter: Override OnLayout to manually position title bar at full width - Form: Set TitleBar.Dock = None so it doesn't participate in normal layout flow Agent-Logs-Url: https://github.com/modern-forms/Modern.Forms/sessions/2dc675de-7074-4e40-a74d-75fbc34933fd Co-authored-by: jpobst <179295+jpobst@users.noreply.github.com>
|
@copilot This fix is not complete. It works for docked and anchored controls, however it does not work for controls that do not have dock or anchor because the layout engine does not use For this test form: public MainForm ()
{
UseSystemDecorations = true;
Controls.Add (new Button { Height = 45, Dock = DockStyle.Top, Text = "Dock - Top", TextAlign = ContentAlignment.MiddleCenter });
Controls.Add (new Button { Top = 55, Text = "Dock - None", TextAlign = ContentAlignment.MiddleCenter });
}It display correctly with
However it is incorrect with
|
After layout runs, offset ALL non-titlebar controls by the title bar height, not just docked/anchored ones. This ensures controls with Dock=None and absolute positioning (e.g. Top=55) are also placed below the managed title bar. Agent-Logs-Url: https://github.com/modern-forms/Modern.Forms/sessions/e2cac2fa-5354-4df8-82d2-01ec185a9018 Co-authored-by: jpobst <179295+jpobst@users.noreply.github.com>
Fixed in e59d8fb. The Note: The |


With managed decorations (default), the
FormTitleBaroccupies the top of the client area, so controls at(0, 0)render behind it. WithUseSystemDecorations = true, the OS title bar is non-client area and controls are fully visible. The two modes should behave consistently.Changes
ControlAdapter.DisplayRectangle: Override to offset the layout rectangle by the visible managed title bar height. This shifts the origin for dock, anchor, and flow layout below the title bar — matching system decoration behavior.ControlAdapter.OnLayout: After base layout runs, manually position theFormTitleBarat(0, 0)spanning full width, then offset ALL other controls (including non-docked, non-anchored, absolute-positioned controls) by the title bar height. This ensures controls withDock = Noneand absolute positioning are also placed below the managed title bar.Remaining work
The
Formconstructor needs to setTitleBar.Dock = DockStyle.Noneafter adding the implicit title bar. Without this, the dock layout engine will reposition the title bar into the offsetDisplayRectangle, creating circular placement. TheFormTitleBarconstructor retainsDock = DockStyle.Topas the default so standalone usage (e.g.TitleBarPanelsample) is unaffected. Additionally, theDisplayRectangleoverride may need to be removed to avoid double-offsetting docked controls (sinceOnLayoutnow offsets all controls post-layout).