unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); private { Private declarations } public { Public declarations } procedure ManipulateControl(WinControl: TWinControl; Shift: TShiftState; X, Y, Precision: integer); //Precision:精度,该方法可以在onmousemove中调用 end;var Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.ManipulateControl(WinControl: TWinControl; Shift: TShiftState; X, Y, Precision: integer); var SC_MANIPULATE: Word; begin //光标在控件的最左侧 if (X <= Precision) and (Y > Precision) and (Y < WinControl.Height - Precision)then begin SC_MANIPULATE := $F001; WinControl.Cursor := crSizeWE; end //光标在控件的最右侧 else if (X >= WinControl.Width - Precision) and (Y > Precision) and (Y < WinControl.Height - Precision) then begin SC_MANIPULATE := $F002; WinControl.Cursor := crSizeWE; end //光标在控件的最上侧 else if (X > Precision) and (X < WinControl.Width - Precision) and (Y <= Precision) then begin SC_MANIPULATE := $F003; WinControl.Cursor := crSizeNS; end //光标在控件的左上角 else if (X <= Precision) and (Y <= Precision) then begin SC_MANIPULATE := $F004; WinControl.Cursor := crSizeNWSE; end //光标在控件的右上角 else if (X >= WinControl.Width-Precision) and (Y <= Precision) then begin SC_MANIPULATE := $F005; WinControl.Cursor := crSizeNESW ; end //光标在控件的最下侧 else if (X > Precision) and (X < WinControl.Width - Precision) and (Y >= WinControl.Height - Precision) then begin SC_MANIPULATE := $F006; WinControl.Cursor := crSizeNS; end //光标在控件的左下角 else if (X <= Precision) and (Y >= WinControl.Height - Precision) then begin SC_MANIPULATE := $F007; WinControl.Cursor := crSizeNESW; end //光标在控件的右下角 else if (X >= WinControl.Width - Precision) and (Y >= WinControl.Height - Precision) then begin SC_MANIPULATE := $F008; WinControl.Cursor := crSizeNWSE; end //光标在控件的客户区(移动整个控件) else if (X > 5) and (Y > 5) and (X < WinControl.Width - 5) and (Y < WinControl.Height - 5)then begin SC_MANIPULATE := $F009; WinControl.Cursor := crSizeAll; end else begin SC_MANIPULATE := $F000; WinControl.Cursor := crDefault; end; if Shift = [ssLeft] then begin ReleaseCapture; WinControl.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0); end; end;procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin Caption := IntToStr(X) + '/' + IntToStr(Y); ManipulateControl((Sender as TWinControl), Shift, X, Y, 10); end;end.
procedure ManipulateControl(WinControl: TControl; Shift: TShiftState; X, Y, Precision: integer); //Precision:精度,该方法可以在onmousemove中调用 var SC_MANIPULATE: Word; begin //光标在控件的最左侧 if (X<=Precision) and (Y>Precision) and (Y<WinControl.Height-Precision) then begin SC_MANIPULATE := $F001; WinControl.Cursor := crSizeWE; end else //光标在控件的最右侧 if (X>=WinControl.Width-Precision) and (Y>Precision) and (Y<WinControl.Height-Precision) then begin SC_MANIPULATE := $F002; WinControl.Cursor := crSizeWE; end else //光标在控件的最上侧 if (X>Precision) and (X<WinControl.Width-Precision) and (Y<=Precision) then begin SC_MANIPULATE := $F003; WinControl.Cursor := crSizeNS; end else //光标在控件的最下侧 if (X>Precision) and (X<WinControl.Width-Precision) and (Y>=WinControl.Height-Precision) then begin SC_MANIPULATE := $F006; WinControl.Cursor := crSizeNS; end else //光标在控件的左上角 if (X<=Precision) and (Y<=Precision) then begin SC_MANIPULATE := $F004; WinControl.Cursor := crSizeNWSE; end else //光标在控件的右上角 if (X>=WinControl.Width-Precision) and (Y<=Precision) then begin SC_MANIPULATE := $F005; WinControl.Cursor := crSizeNESW ; end else //光标在控件的左下角 if (X<=Precision) and (Y>=WinControl.Height-Precision) then begin SC_MANIPULATE := $F007; WinControl.Cursor := crSizeNESW; end else //光标在控件的右下角 if (X>=WinControl.Width-Precision) and (Y>=WinControl.Height-Precision) then begin SC_MANIPULATE := $F008; WinControl.Cursor := crSizeNWSE; end else //光标在控件的客户区(移动整个控件) if (X>5) and (Y>5) and (X<WinControl.Width-5) and (Y<WinControl.Height-5) then begin SC_MANIPULATE := $F009; WinControl.Cursor := crSizeAll; end else begin SC_MANIPULATE := $F000; WinControl.Cursor := crDefault; end; if Shift=[ssLeft] then begin ReleaseCapture; WinControl.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0); end; end;//调用方法: procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin Caption := IntToStr(X) + '/' + IntToStr(Y); ManipulateControl((Panel1 as TwinControl), Shift, X, Y, 10); end;注意: 只有从TWinControl继承的控件,才能用此方法。
procedure Tleafrecordsure.Label2MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
showmessage('dddddddd'+inttostr(x)+'dd'+inttostr(y));
end;
procedure Tleafrecordsure.Label2MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
label2.Left:=x;
label2.Top:=y;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
procedure ManipulateControl(WinControl: TWinControl; Shift: TShiftState; X, Y, Precision: integer);
//Precision:精度,该方法可以在onmousemove中调用
end;var
Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.ManipulateControl(WinControl: TWinControl;
Shift: TShiftState; X, Y, Precision: integer);
var SC_MANIPULATE: Word;
begin
//光标在控件的最左侧
if (X <= Precision) and (Y > Precision) and (Y < WinControl.Height - Precision)then
begin
SC_MANIPULATE := $F001;
WinControl.Cursor := crSizeWE;
end
//光标在控件的最右侧
else if (X >= WinControl.Width - Precision) and (Y > Precision) and (Y < WinControl.Height - Precision) then
begin
SC_MANIPULATE := $F002;
WinControl.Cursor := crSizeWE;
end
//光标在控件的最上侧
else if (X > Precision) and (X < WinControl.Width - Precision) and (Y <= Precision) then
begin
SC_MANIPULATE := $F003;
WinControl.Cursor := crSizeNS;
end
//光标在控件的左上角
else if (X <= Precision) and (Y <= Precision) then
begin
SC_MANIPULATE := $F004;
WinControl.Cursor := crSizeNWSE;
end
//光标在控件的右上角
else if (X >= WinControl.Width-Precision) and (Y <= Precision) then
begin
SC_MANIPULATE := $F005;
WinControl.Cursor := crSizeNESW ;
end
//光标在控件的最下侧
else if (X > Precision) and (X < WinControl.Width - Precision) and (Y >= WinControl.Height - Precision) then
begin
SC_MANIPULATE := $F006;
WinControl.Cursor := crSizeNS;
end
//光标在控件的左下角
else if (X <= Precision) and (Y >= WinControl.Height - Precision) then
begin
SC_MANIPULATE := $F007;
WinControl.Cursor := crSizeNESW;
end
//光标在控件的右下角
else if (X >= WinControl.Width - Precision) and (Y >= WinControl.Height - Precision) then
begin
SC_MANIPULATE := $F008;
WinControl.Cursor := crSizeNWSE;
end
//光标在控件的客户区(移动整个控件)
else if (X > 5) and (Y > 5) and (X < WinControl.Width - 5) and (Y < WinControl.Height - 5)then
begin
SC_MANIPULATE := $F009;
WinControl.Cursor := crSizeAll;
end
else
begin
SC_MANIPULATE := $F000;
WinControl.Cursor := crDefault;
end; if Shift = [ssLeft] then
begin
ReleaseCapture;
WinControl.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);
end;
end;procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Caption := IntToStr(X) + '/' + IntToStr(Y);
ManipulateControl((Sender as TWinControl), Shift, X, Y, 10);
end;end.
X, Y, Precision: integer);
//Precision:精度,该方法可以在onmousemove中调用
var
SC_MANIPULATE: Word;
begin
//光标在控件的最左侧
if (X<=Precision) and (Y>Precision) and (Y<WinControl.Height-Precision) then
begin
SC_MANIPULATE := $F001;
WinControl.Cursor := crSizeWE; end
else
//光标在控件的最右侧
if (X>=WinControl.Width-Precision) and (Y>Precision) and (Y<WinControl.Height-Precision) then
begin
SC_MANIPULATE := $F002;
WinControl.Cursor := crSizeWE;
end
else
//光标在控件的最上侧
if (X>Precision) and (X<WinControl.Width-Precision) and (Y<=Precision) then
begin
SC_MANIPULATE := $F003;
WinControl.Cursor := crSizeNS;
end
else
//光标在控件的最下侧
if (X>Precision) and (X<WinControl.Width-Precision) and (Y>=WinControl.Height-Precision) then
begin
SC_MANIPULATE := $F006;
WinControl.Cursor := crSizeNS;
end
else
//光标在控件的左上角
if (X<=Precision) and (Y<=Precision) then
begin
SC_MANIPULATE := $F004;
WinControl.Cursor := crSizeNWSE;
end
else
//光标在控件的右上角
if (X>=WinControl.Width-Precision) and (Y<=Precision) then
begin
SC_MANIPULATE := $F005;
WinControl.Cursor := crSizeNESW ;
end
else
//光标在控件的左下角
if (X<=Precision) and (Y>=WinControl.Height-Precision) then
begin
SC_MANIPULATE := $F007;
WinControl.Cursor := crSizeNESW;
end
else
//光标在控件的右下角
if (X>=WinControl.Width-Precision) and (Y>=WinControl.Height-Precision) then
begin
SC_MANIPULATE := $F008;
WinControl.Cursor := crSizeNWSE;
end
else
//光标在控件的客户区(移动整个控件)
if (X>5) and (Y>5) and (X<WinControl.Width-5) and
(Y<WinControl.Height-5) then
begin
SC_MANIPULATE := $F009;
WinControl.Cursor := crSizeAll;
end
else
begin
SC_MANIPULATE := $F000;
WinControl.Cursor := crDefault;
end;
if Shift=[ssLeft] then
begin
ReleaseCapture;
WinControl.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);
end;
end;//调用方法:
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Caption := IntToStr(X) + '/' + IntToStr(Y);
ManipulateControl((Panel1 as TwinControl), Shift, X, Y, 10);
end;注意: 只有从TWinControl继承的控件,才能用此方法。