1个回答
展开全部
unit drag2u;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls ;
type
Tfrmtest = class(TForm)
Button1: TButton;
procedure Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmtest: Tfrmtest;
tb: TButton;
delx,dely: Integer;
msDown: Boolean;
implementation
{$R *.DFM}
procedure Tfrmtest.Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
msDown:=true;
delx:=x;
dely:=y;
end;
procedure Tfrmtest.Button1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
msDown:=false;
end;
procedure Tfrmtest.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if msDown then
begin
tb:=Sender as TButton ;
tb.left:=tb.left+x-delx;
tb.Top :=tb.top +y-dely;
end;
end;
procedure Tfrmtest.FormCreate(Sender: TObject);
begin
msDown:=false;
end;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls ;
type
Tfrmtest = class(TForm)
Button1: TButton;
procedure Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmtest: Tfrmtest;
tb: TButton;
delx,dely: Integer;
msDown: Boolean;
implementation
{$R *.DFM}
procedure Tfrmtest.Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
msDown:=true;
delx:=x;
dely:=y;
end;
procedure Tfrmtest.Button1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
msDown:=false;
end;
procedure Tfrmtest.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if msDown then
begin
tb:=Sender as TButton ;
tb.left:=tb.left+x-delx;
tb.Top :=tb.top +y-dely;
end;
end;
procedure Tfrmtest.FormCreate(Sender: TObject);
begin
msDown:=false;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询