可以利用窗体和控件的停泊功能实现。
这是主窗体:
unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons, ComCtrls;
type
TForm1 = class(TForm)
LeftDockPanel: TPanel;
LeftSplitter: TSplitter;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
SpeedButton1: TSpeedButton;
StatusBar1: TStatusBar;
BitBtn3: TBitBtn;
procedure LeftDockPanelDockOver(Sender: TObject;
Source: TDragDockObject; X, Y: Integer; State: TDragState;
var Accept: Boolean);
procedure LeftDockPanelDockDrop(Sender: TObject;
Source: TDragDockObject; X, Y: Integer);
procedure BitBtn1Click(Sender: TObject);
procedure LeftDockPanelUnDock(Sender: TObject; Client: TControl;
NewTarget: TWinControl; var Allow: Boolean);
procedure BitBtn2Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
HOLDCURSOR:HCURSOR;// Cursor temp Var
implementation
uses DocUnit;
{$R *.dfm}
procedure TForm1.LeftDockPanelDockOver(Sender: TObject;
Source: TDragDockObject; X, Y: Integer; State: TDragState;
var Accept: Boolean);
var
ARect: TRect;
begin
Accept := Source.Control is TDockableForm;
if Accept then
begin
//修改预览停靠位置
ARect.TopLeft := LeftDockPanel.ClientToScreen(Point(0, 0));
ARect.BottomRight := LeftDockPanel.ClientToScreen(
Point(Self.ClientWidth div 4, LeftDockPanel.Height));
Source.DockRect := ARect;
end;
end;
procedure TForm1.LeftDockPanelDockDrop(Sender: TObject;
Source: TDragDockObject; X, Y: Integer);
begin
LeftDockPanel.Width := ClientWidth div 4;
LeftSplitter.Left := LeftDockPanel.Width + LeftSplitter.Width;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
Var
DockMe:Boolean;
begin
DockableForm.show;
DockableForm.Visible:=true;
DockMe:=DockableForm.ManualDock(Form1.LeftDockPanel,nil,alleft);
if not DockMe then
ShowMessage('Don''t Dock Form2 to LeftPanel');
end;
procedure TForm1.LeftDockPanelUnDock(Sender: TObject; Client: TControl;
NewTarget: TWinControl; var Allow: Boolean);
begin
LeftDockPanel.Width:=0;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
form1.ScaleBy(4,3);
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
form1.ScaleBy(3,4);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
HNEWCURSOR:HCURSOR; // Cursor Temp var
begin
BitBtn3.Caption:='关闭光标';
HNEWCURSOR:=LOADCURSORFROMFILE('D:/WINNT/Cursors/horse.ani');
{调用API函数装载动画光标文件,ANI文件路径请根据自己的实际情况进行调整}
HOLDCURSOR:=SETCLASSLONG(FORM1.Handle,GCL_HCURSOR,HNEWCURSOR);
{把原光标储存起来以备以后的恢复}
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
HOLDCURSOR:=SETCLASSLONG(FORM1.HANDLE,GCL_HCURSOR,HOLDCURSOR);
end;
end.
这个第二个窗体
unit DocUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TDockableForm = class(TForm)
Image1: TImage;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
DockableForm: TDockableForm;
implementation
uses MainUnit;
{$R *.dfm}
procedure TDockableForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Form1.LeftDockPanel.Width := 0;
Action := caHide
end;
end.
运行时第二个窗体自动被放到第一个窗体中停泊。
我们还可以利用TabControl和PageControl等控件停泊多个窗体,就像delphi的代码编辑器一样了