这在Delphi Docking中是否可行,还是需要自定义拖放?

时间:2017-06-28 05:53:17

标签: delphi drag-and-drop docking

请参考下图:

  • Panel1和Panel2可停靠。
  • 右侧的面板是停靠站点。
  • 我知道将panel1和panel2逐个拖动到右侧面板时默认对接的工作原理。

enter image description here

我的问题:我可以控制停靠预览矩形和最终停靠矩形,以便停靠的面板保持其高度并占据右侧面板的整个宽度吗?换句话说,我可以创建一个管理单元类型效果,在第一个面板对接时,它位于右面板的顶部,具有自己的高度。然后停靠的第二个面板在其下方以自己的高度捕捉?

我怀疑我需要使用自己的拖放而不是对接才能执行那种拖放操作。我想使用Docking,因为它有很好的目标预览矩形功能,我将不得不在Drag and Drop中执行我自己的代码。

1 个答案:

答案 0 :(得分:1)

以下是您可以实现此目的的一个示例

procedure TForm3.ScrollBox1DockDrop(Sender: TObject; Source: TDragDockObject; X,
  Y: Integer);
begin
  //Change the dropped component (source) Align property to alTop to achieve top 
  //alignment of docked control
  Source.Control.Align := alTop;
end;

procedure TForm3.ScrollBox1UnDock(Sender: TObject; Client: TControl;
  NewTarget: TWinControl; var Allow: Boolean);
begin
  //Reset Align property to alNone to revert undocked control to original size
  //NOTE: Changing Source.DocRect like in OnDockOver event below will also change
  //original size of the control. So when undocked it will no longer have same 
  //dimensions as it did before docking 

  Client.Align := alNone;
end;

//Here we can manipulate the size of DockRect to get better preview of docked component.
//NOTE: Changing Source.DocRect like in OnDockOver event below will also change
//original size of the control. So when undocked it will no longer have same 
//dimensions as it did before docking
procedure TForm3.ScrollBox1DockOver(Sender: TObject; Source: TDragDockObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
var
  ARect: TRect;
begin
  Accept := Source.Control is TPanel;
  if Accept then
  begin
    ARect.TopLeft := (Sender as TScrollBox).ClientToScreen(Point(0,Y));
    ARect.BottomRight := (Sender as TScrollBox).ClientToScreen(Point((Sender as TScrollBox).ClientWidth, Source.Control.Height+Y));
    Source.DockRect := ARect;
  end;
end;

此外,您可能需要查看此问题以获取有关对接的更多信息,包括对某些第三方组件的建议

here