The close button appears on my docked control after reinstalling

I have a drawing box that 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 in a panel with DockSite set to True . I experience rather strange behavior when I dock a paint after detaching it to a floating shape. A button to close a floating form appears inside the panel. I added two screenshots. One from the initial state, and one after docking paints. What am I missing?

The initial state:

Before undocking

After docking:

After docking


UPDATE After using the TLama solution, here is the result.

After docking Using new dock manager

+6
source share
2 answers

You have not missed anything. This is how the default dock manager implementation works. He just wants to have a grabber with a close button available on the dock that uses it. What you can do is implement your own dock manager and redefine its AdjustDockRect method, which controls the size of the docking area and where the default implementation is dock manager made the capture space with the button closed. If you don’t want this grabber, just save the size of the rectangle of the dock area as it was passed to the method, the size of the entire dock site. In other words, do nothing in this method.

This is for the functional part of the grabber, but with the exception that you need to intercept its hard-coded pattern. To do this, you need to override the PaintDockFrame event PaintDockFrame and, as before, do nothing.

Here is a sample code:

 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 a custom dock manager (see below for a note on the UseDockManager property:

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

Attention!

As you can see from several sources, you should set the UseDockManager property of your False dock panel at design time. I don’t know why, but from the quick tests I did, some of the dock manager’s custom event methods weren’t running when I didn’t set this property at design time ( AdjustDockRect event handler worked fine without even doing it, but I I personally would not rely on him).

+3
source

Instead of using the panel as the target of the dock, use TPageControl and hide the tab from the created tab. Because the page control usually has visible tabs, the delete handle is not displayed. Unfortunately, when you hide the tab of the tab of the tab, the sheet itself is also hidden. Therefore, 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; 
+1
source

All Articles