unit Unit1;
interface
uses
IniFiles,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, jpeg;
type
TForm1 =
class(TForm)
Button1: TButton;
Edit1: TEdit;
Panel1: TPanel;
Button2: TButton;
chkPositionRunTime: TCheckBox;
Image1: TImage;
procedure ControlMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ControlMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure ControlMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
inReposition : boolean;
oldPos: TPoint;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ControlMouseDown(
Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
if (chkPositionRunTime.Checked)
AND (Sender
is TWinControl)
then
begin
inReposition:=True;
SetCapture(TWinControl(Sender).Handle);
GetCursorPos(oldPos);
end;
end;
procedure TForm1.ControlMouseMove(
Sender: TObject;
Shift: TShiftState;
X, Y: Integer);
var
newPos: TPoint;
frmPoint : TPoint;
begin
if inReposition
then
begin
with TWinControl(Sender)
do
begin
GetCursorPos(newPos);
begin
Screen.Cursor := crSize;
Left := Left - oldPos.X + newPos.X;
Top := Top - oldPos.Y + newPos.Y;
oldPos := newPos;
end;
end;
end;
end;
procedure TForm1.ControlMouseUp(
Sender: TObject;
Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if inReposition
then
begin
Screen.Cursor := crDefault;
ReleaseCapture;
inReposition := False;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
Begin
Button1.OnMouseDown := ControlMouseDown;
Button1.OnMouseMove := ControlMouseMove;
Button1.OnMouseUp := ControlMouseUp;
Edit1.OnMouseDown := ControlMouseDown;
Edit1.OnMouseMove := ControlMouseMove;
Edit1.OnMouseUp := ControlMouseUp;
Panel1.OnMouseDown := ControlMouseDown;
Panel1.OnMouseMove := ControlMouseMove;
Panel1.OnMouseUp := ControlMouseUp;
Button2.OnMouseDown := ControlMouseDown;
Button2.OnMouseMove := ControlMouseMove;
Button2.OnMouseUp := ControlMouseUp;
Image1.OnMouseDown := ControlMouseDown;
Image1.OnMouseMove := ControlMouseMove;
Image1.OnMouseUp := ControlMouseUp;
end;
end.