Skip to main content

Controlling Docking Operations

  • 3 minutes to read

The Docking Operations and Performing Docking Operations via Code topics provide an overview of docking operations available and how they can be performed via code. This topic explains how you can respond to docking operations performed by end-users and how to provide custom functionality for such operations.

Responding to Docking Operations Performed by End-Users


Dock controls provide a number of events that fire in response to docking operations performed against them. These events can be handled if you need to perform specific actions immediately after such operations are completed. For instance, you may need to update the control’s layout or contents when it is docked or made to float.

The OnDock, OnMakeFloating and OnUnDock events fire in response to docking a control to another dock control, making it float and undocking it respectively. Also, dock controls provide a OnLayoutChanged event that is raised when the layout of the control’s children is modified. If you need to respond to any dock control layout changes in an application, handle the OnLayoutChanged event of the docking manager.

There are two more events provided by dock controls that fire when starting a docking operation and immediately after it has been completed. These are the OnStartDocking and OnEndDocking events.

Providing Custom Constraints for Docking Operations


The AllowDock, AllowDockClients, AllowFloating and Dockable properties of dock controls enable you to specify constraints on docking operations performed on a dock control. However, using these properties may not be enough. For instance, the AllowDock property specifies how this control can be docked to other controls. However, you may have a need to specify different logic for docking a control to different targets. In such cases, handle the OnDocking event. This event is raised repeatedly when performing a docking operation. It enables you to specify whether docking to the current position is allowed. After the event handler has been executed, the target dock control’s OnCanDocking event is raised. Thus, the docking operation target can also cancel the docking operation being performed.

The following sample code handles the OnDocking event to allow panel docking only when the target is a dock site or layout site. You can assign such an event handler to the OnDocking event of all panels. As a result, panels will not be docked to one another and container sites will not be created.

procedure TForm1.dxDockPanel2Docking(Sender: TdxCustomDockControl;  Zone: TdxZone; X, Y: Integer; var Accept: Boolean);
begin
  if Zone = nil then Exit;
  if (Zone.Owner is TdxDockSite) or
     (Zone.Owner is TdxLayoutDockSite) then
    Accept := True
  else
    Accept := False;
end;

Controlling Double-Click Docking Operations


End-users can perform docking operations by double-clicking captions of dock controls. When a control is a child of a tab container, its corresponding tab must be double-clicked. Note that this functionality is only available when the doDblClickDocking option is enabled. This option is available via the Options property of the docking manager.

A double-click docking operation floats a control. If the control’s caption is double-clicked once again, the previous position of the control is restored. You can provide custom behaviors for these operations by handling the OnStoreDockPosition and OnRestoreDockPosition events of dock controls. Please refer to the appropriate event descriptions for additional information and code samples.

See Also