Skip to main content

Controlling Resizing Operations

  • 3 minutes to read

The basics of performing resizing operations on dock controls are explained in the Resizing Operations topic. This topic provides information on how to respond to such operations and how to provide resizing constraints.

Responding to Resizing Operations Performed by End-Users


Dock controls provide a number of events that enable you to respond to control resizing. When the resizing process starts, the OnStartResizing event of the dock control is raised. Note that this happens immediately after an end-user has pressed the mouse button when the pointer is over a resize zone. When the mouse pointer moves, the OnResizing event fires. It enables you to perform specific actions during the resizing process. When the mouse button is released, the dragged edge is moved to a new position and the OnEndResizing event is raised.

The sample code below shows an example of handling the OnStartResizing, OnResizing and OnEndResizing events. The first is used to display a message within the status bar. The second changes the message to display the potential width of the dock control (only horizontal resizing is processed). The last event is used to clear the status bar.

procedure TForm1.dxDockPanel2StartResizing(Sender: TdxCustomDockControl; Zone: TdxZone; X, Y: Integer);
begin
  StatusBar1.SimpleText := 'Drag the border to resize the dock control';
end;
procedure TForm1.dxDockPanel2Resizing(Sender: TdxCustomDockControl; Zone: TdxZone; X, Y: Integer);
var AWidthDelta, ANewWidth: Integer;
begin
  if Zone.Direction = zdVertical then
  begin
    AWidthDelta := Zone.GetResizingSelection(Mouse.CursorPos).Left - Sender.ClientToScreen(Zone.Rectangle.TopLeft).X;
    if Zone.DockType = dtRight then
      ANewWidth := Sender.Width + AWidthDelta
    else
      ANewWidth := Sender.Width - AWidthDelta;
    StatusBar1.SimpleText := 'New Width: ' + IntToStr(ANewWidth);
  end;
end;
procedure TForm1.dxDockPanel2EndResizing(Sender: TdxCustomDockControl; Zone: TdxZone; X, Y: Integer);
begin
  StatusBar1.SimpleText := '';
end;

The image below shows the result of handling events in such a manner. Note the status bar text.

To respond to changes in dock control dimensions, you can also handle the OnResize event. This event is useful since it fires when the dock control is floating and its owning float form is resized. Other events do not fire in such a case.

Providing Custom Resizing Constraints


You can provide constraints for resizing dock controls. For instance, you can specify the maximum and minimum allowed dimension or implement a resizing step. To do so, handle the OnCanResize event of the dock control. The event repeatedly fires during resizing. It provides a parameter that enables you to specify whether resizing to the current position is allowed.

Please refer to the OnCanResize event description for details on implementing resizing constraints and code samples.

See Also