我们用一个例子来演示这个类的用法,建一个工程,将TDragClass的单元加入主窗体单元中,代码如下:
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, ExtCtrls, Buttons,uDrag,uDragPoint, jpeg;
type
TForm1 = class(TForm)
Bevel1: TBevel;
Button3: TButton; //指定用何种方式移动和拉动
Edit2: TEdit;//用于设定跳跃式移动的幅度
Button4: TButton;//确定Edit2中的内容
Button1: TButton;//点击该按钮,加入下面的控件,实现控件移动
Panel1: TPanel;
Shape1: TShape;
Image1: TImage;
Button2: TButton;
Edit1: TEdit;
StaticText1: TStaticText;
Shape2: TShape;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
MyDrag:TDragClass;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
myDrag.addControl(Edit1);
myDrag.addControl(Button2);
myDrag.addControl(Shape1);
myDrag.addControl(Image1);
myDrag.addControl(Panel1);
myDrag.addControl(BitBtn1);
myDrag.addControl(shape2);
myDrag.addControl(BitBtn2);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
myDrag:=TDragClass.create(self);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Assigned(myDrag) then
MyDrag.Free;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
myDrag.isMoveStep:=not myDrag.isMoveStep;
if myDrag.isMoveStep then
Button3.Caption:='连接式移动'
else
Button3.Caption:='跳跃式移动';
end;
procedure TForm1.Button4Click(Sender: TObject);
var value:integer;
begin
if TryStrtoInt(Edit2.Text,value) then
myDrag.MoveStep:=value;
end;
procedure TForm1.FormClick(Sender: TObject);
begin
myDrag.SetPointVisible(false);
end;
end.
运行程序,点击Button1按钮,看看如何,下面的控件是不是都可以移动了呢,再点击Button3,控件的移动是不是变得不连续了呢,再输入Edit2的值,然后点确定,控件移动的不连续性是不是变化了呢。
至此这个控件移动类讲解完毕,但还有很多改善的地方,有兴趣自己改吧。还是那句话,希望对你有用。
本文地址:http://com.8s8s.com/it/it4739.htm