Table of Contents

Dock manager

ExDockManager lays out a window into the main content (Document) and tool panels (ExDockPanel) docked to the left, right, top or bottom, like the tool windows of Visual Studio or Rider.

Layout

  • Left and right zones span the full height, top and bottom zones lie between them.
  • A zone splits into nested rows and columns of groups. Several panels in one group are tabs.
  • The user resizes zones and groups with splitters.
  • The close button (×) hides a panel. The pin collapses its group to the strip at the edge of the window, and a click on the strip slides the panel out (auto-hide).
  • Dragging the caption moves the whole group, dragging a tab moves one panel. Docking guides show where it lands:
    • a compass over a group adds a tab (center) or splits the group (arrows);
    • a compass over the document splits the document, so the panel takes only the height or width of the document, not the whole side;
    • the guides at the edges of the window add a column or a row at the outer edge of the zone.
  • Dropped outside the guides, the panel becomes a floating window (AllowFloating).

The guides at the edges stay visible during the drag. A compass near an edge moves away from them and stays while the cursor is on it.

Setting it up

The manager is created in code, it isn't in the toolbox. Dock it with DockStyle.Fill, move the content of the form into Document, add all panels and only then load the saved layout:

var dock = new ExDockManager { Dock = DockStyle.Fill };
Controls.Remove(content);
dock.Document.Controls.Add(content);              // main content of the window
Controls.Add(dock);
dock.BringToFront();                              // Fill after the docked tool strips

var errors = new ExDockPanel("errors", "Error List");
errors.Controls.Add(new ErrorListView { Dock = DockStyle.Fill });
dock.AddPanel(errors, ExDockSide.Bottom);         // AddPanel(panel, tabWith) adds a tab
dock.AddPanel(output, errors, ExDockSide.Right);  // splits the group of errors, output on its right
dock.SetZoneSize(ExDockSide.Bottom, 180);
dock.HidePanel(errors);                           // shown later by ShowPanel(errors)

dock.LoadLayout(settings.DockLayout);             // empty = keep, invalid = FormatException

SetZoneSize takes logical pixels, the manager scales them by the DPI of the window.

Saving the layout

Panels are identified by their Key. SaveLayout returns the layout as a single-line XML string with sizes in logical pixels, ready for the application settings:

protected override void OnFormClosing(FormClosingEventArgs e)
{
    settings.DockLayout = dock.SaveLayout();
    base.OnFormClosing(e);
}

LoadLayout keeps the current layout for an empty string and throws FormatException for an invalid one without changing the layout. Panels missing in the saved layout stay where the code put them and keys of panels that weren't added are ignored, so a new version of the application can add or remove panels.

Changing the layout from code

ShowPanel, HidePanel, DockPanel, FloatPanel and SetAutoHide change the layout from code. The events tell the application what the user did:

  • PanelStateChanged: a panel was shown, hidden, docked elsewhere, collapsed, floated or removed, for example to update a checked menu item;
  • PanelClosing: the user hides a panel, the event can cancel it;
  • ActivePanelChanged: the active panel (ActivePanel) changed.

Texts and themes

The library has no UI texts of its own language. The tool tips and the window menu of the panels take their texts from Strings:

dock.Strings = new ExDockStrings { Hide = "Skryť", AutoHide = "Automaticky skryť" /* ... */ };

The manager applies a theme to the document and to all panels, including the hidden and floating ones (IThemeable). It owns its panels: disposing the manager disposes all of them, also the hidden ones.

Try it

ExControlsTester shows the dock manager in the menu Okno, Dock manager.