home *** CD-ROM | disk | FTP | other *** search
- unit ButtonMUnit;
- { This project implements Borland/Inprise programming tip #2909
- to let the user move a panel around at runtime. The text of the
- tip is shown in the comment below... }
-
- (*
- PRODUCT : Delphi NUMBER : 2909
- VERSION : All
- OS : Windows/Win32
- DATE : June 1, 1996
-
- TITLE : How to click and move components at runtime.
-
- Q: How can I program a component, such as a TPanel, so that I
- can move it around with a click and drag of the mouse?
-
- A: This code goes on the OnMouseDown event of the component in
- question (a TPanel in this case):
-
- procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
-
- Shift: TShiftState; X, Y: Integer);
- const
- SC_DragMove = $F012; { a magic number }
-
- begin
- ReleaseCapture;
- panel1.perform(WM_SysCommand, SC_DragMove, 0);
- end;
-
- DISCLAIMER: You have the right to use this technical information
- subject to the terms of the No-Nonsense License Statement that
- you received with the Borland product to which this information
- pertains.
- *)
-
- interface
-
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ExtCtrls, StdCtrls;
-
- type
- TForm1 = class(TForm)
- Button1: TButton;
- procedure Button1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure Button1Click(Sender: TObject);
- procedure Button1MouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- const
- SC_DragMove = $F012; { a magic number }
- begin
- ReleaseCapture;
- button1.perform(WM_SysCommand, SC_DragMove, 0);
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- ShowMessage( 'MouseClick!');
- end;
-
- procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- ShowMessage( 'MouseUp' );
- end;
-
- end.
-