unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ImgList, ToolWin, Menus, StdCtrls, jpeg, ExtCtrls;
type
TForm1 = class(TForm)
CoolBar1: TCoolBar;
ImageList1: TImageList;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
ScrollBox1: TScrollBox;
StatusBar1: TStatusBar;
Image1: TImage;
ToolButton3: TToolButton;
procedure ToolButton1Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ToolButton2Click(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
procedure ToolButton5Click(Sender: TObject);
procedure ToolButton6Click(Sender: TObject);
procedure ToolButton7Click(Sender: TObject);
procedure ToolButton8Click(Sender: TObject);
procedure ToolButton3Click(Sender: TObject);
private
{ Private declarations }
PX,PY:Integer;
IsMove:boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses About;
{$R *.dfm}
procedure TForm1.ToolButton1Click(Sender: TObject);
begin
with TButton.Create(ScrollBox1) do
begin
Caption:='新按钮';
Parent :=ScrollBox1;
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
PX:=X;
PY:=Y;
IsMove:=true;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
PX:=0;
PY:=0;
IsMove:=false;
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if IsMove=false then exit;
with (Sender as TControl) do
begin
Left :=Left +X-PX;
Top :=Top +Y-Py;
end;
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
IsMove:=false;
end;
procedure TForm1.ToolButton2Click(Sender: TObject);
begin
with TCheckBox.Create(ScrollBox1) do
begin
Caption:='新复选按钮';
Parent :=ScrollBox1;
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;
procedure TForm1.ToolButton4Click(Sender: TObject);
begin
with TEdit.Create(ScrollBox1) do
begin
Text:='新编辑框';
Parent :=ScrollBox1;
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;
procedure TForm1.ToolButton5Click(Sender: TObject);
begin
with TLabel.Create(ScrollBox1) do
begin
Caption:='新标签';
Parent :=ScrollBox1;
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;
procedure TForm1.ToolButton6Click(Sender: TObject);
begin
with TListBox.Create(ScrollBox1) do
begin
Parent :=ScrollBox1;
Items.Add('新列表框');
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;
procedure TForm1.ToolButton7Click(Sender: TObject);
begin
with TMemo.Create(ScrollBox1) do
begin
Text:='新文本框';
Parent :=ScrollBox1;
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;
procedure TForm1.ToolButton8Click(Sender: TObject);
begin
with TRadioButton.Create(ScrollBox1) do
begin
Caption:='新选择框';
Parent :=ScrollBox1;
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;
procedure TForm1.ToolButton3Click(Sender: TObject);
begin
Form_About.ShowModal;
end;
end.
贴一段代码,自己看看,应该很简单的