Question

I have a paint box which I want the user to be able to undock and move around. So I set its DragKind to dkDock and its DragMode to dmAutomatic, and put it inside a panel with DockSite set to True. I'm experiencing a rather odd behavior when I dock the paint box after having undocked it to a floating form. The close button of the floating form appears inside the panel. I've attached two screenshots. One from the original state, and one after docking the paint box again. What am I missing?

Original State:

Before undocking

After docking:

After docking


UPDATE After using TLama's solution, here's the result.

After Docking ; Using new dock manager

Was it helpful?

Solution

You're not missing anything. That's how the default dock manager implementation works. It just wants to have grabber with the close button available on dock site, which uses it. What you can do, is implement your own dock manager and override its AdjustDockRect method, which controls the size of docking zone and where is in default dock manager implementation made a space for grabber with close button. If you don't want that grabber, just keep the size of dock zone rectangle as it was passed to the method, in size of the whole dock site. In other words, do nothing in that method override.

That's for the functional part of the grabber, but except that you need to intercept hardcoded drawing of it. To do so, you need to override the PaintDockFrame event method and like before, do just nothing there.

Here's a code sample:

type
  TNoGrabDockManager = class(TDockTree)
  protected
    procedure AdjustDockRect(Control: TControl; var ARect: TRect); override;
    procedure PaintDockFrame(Canvas: TCanvas; Control: TControl;
      const ARect: TRect); override;
  end;

implementation

{ TNoGrabDockManager }

procedure TNoGrabDockManager.AdjustDockRect(Control: TControl; var ARect: TRect);
begin
  // here you can make space for a grabber by shifting top or left position
  // of the ARect parameter, which is by default set to the whole dock site
  // bounds size, so if you do nothing here, there will be no grabber
end;

procedure TNoGrabDockManager.PaintDockFrame(Canvas: TCanvas; Control: TControl;
  const ARect: TRect);
begin
  // in this event method, the grabber with that close button are drawn, so
  // as in case of disabling grabber functionality do precisely nothing for
  // drawing it here, that will make it visually disappear
end;

Here's how to use such custom dock manager (see below for note about UseDockManager property):

procedure TForm1.FormCreate(Sender: TObject);
begin
  Panel1.DockManager := TNoGrabDockManager.Create(Panel1);
  Panel1.UseDockManager := True;
end;

Important

As few sources suggest, you should set the UseDockManager property of your dock panel to False at design time. I don't know why, but from quick tests I've made, some of the event methods of the custom dock manager were not fired when I didn't have set that property at design time (the AdjustDockRect event method worked properly even without doing so, but I wouldn't personally rely on it).

OTHER TIPS

Rather than using a panel as the dock target, use a TPageControl and hide the tab from the generated tab sheet. Since a page control normally has visible tabs, the delete handle is not displayed. Unfortunately, when you hide a tab sheet's tab, the sheet itself is also hidden. So you must save and restore it by adding the following OnDockDrop event:

procedure TForm2.PageControl1DockDrop(Sender: TObject; Source: TDragDockObject;
  X, Y: Integer);
var
  ix: Integer;
begin
  ix := PageControl1.ActivePageIndex;
  PageControl1.ActivePage.TabVisible := false;
  PageControl1.ActivePageIndex := ix;
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top