Title: Moving (draging) components on Form
Question: How to move controls (components) on form
Answer:
With this part of code you can move TWinControl(s) only.
Assign Panel1MouseMove Event to the other controls Edit1, Button1, RadioButton1 and see the result!!!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Edit1: TEdit;
Button1: TButton;
RadioButton1: TRadioButton;
Label1: TLabel;
procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
const
SC_MOVE = $F012;
begin
ReleaseCapture;
(sender as TWinControl).perform(WM_SysCommand, SC_MOVE, 0);
end;
end.