先用几个Panel或其它控件作为Dock Site(即设控件DockSite属性为true);
再把需要Dock的控件DragKind属性设为dkDock,DragMode属性设为dmAutomatic
(自己判断Dock是否开始也行,即使用BeginDrag)
以下范例演示Panel在Form上的Dock
dfm:
--------------------------------------------------
object Form1: TForm1
Left = 192
Top = 107
Width = 498
Height = 245
Caption = 'Form1'
Color = clBtnFace
DockSite = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 72
Top = 40
Width = 161
Height = 105
Caption = 'Panel1'
DragKind = dkDock
TabOrder = 0
OnMouseDown = Panel1MouseDown
end
object Panel2: TPanel
Left = 256
Top = 40
Width = 169
Height = 105
Caption = 'Panel2'
DragKind = dkDock
DragMode = dmAutomatic
TabOrder = 1
end
end
------------------------------------------------------------------
pas:
------------------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
self.Panel1.BeginDrag(true);
end;
end.
--------------------------------------------------------------------