home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / handson / archive / Issue150 / delphi / copydlph.exe / ButtonMover / ButtonMUnit.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1998-12-24  |  2.2 KB  |  86 lines

  1. unit ButtonMUnit;
  2. { This project implements Borland/Inprise programming tip #2909
  3.   to let the user move a panel around at runtime. The text of the
  4.   tip is shown in the comment below... }
  5.    
  6. (*
  7.   PRODUCT  :  Delphi                                 NUMBER  :  2909
  8.   VERSION  :  All
  9.        OS  :  Windows/Win32
  10.      DATE  :  June 1, 1996
  11.  
  12.     TITLE  :  How to click and move components at runtime.
  13.  
  14. Q:  How can I program a component, such as a TPanel, so that I
  15. can move it around with a click and drag of the mouse?
  16.  
  17. A:  This code goes on the OnMouseDown event of the component in
  18. question (a TPanel in this case):
  19.  
  20. procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  21.  
  22.     Shift: TShiftState; X, Y: Integer);
  23. const
  24.   SC_DragMove = $F012;  { a magic number }
  25.  
  26. begin
  27.   ReleaseCapture;
  28.   panel1.perform(WM_SysCommand, SC_DragMove, 0);
  29. end;
  30.  
  31. DISCLAIMER: You have the right to use this technical information
  32. subject to the terms of the No-Nonsense License Statement that
  33. you received with the Borland product to which this information
  34. pertains.
  35. *)
  36.  
  37. interface
  38.  
  39.  
  40. uses
  41.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  42.   ExtCtrls, StdCtrls;
  43.  
  44. type
  45.   TForm1 = class(TForm)
  46.     Button1: TButton;
  47.     procedure Button1MouseDown(Sender: TObject; Button: TMouseButton;
  48.       Shift: TShiftState; X, Y: Integer);
  49.     procedure Button1Click(Sender: TObject);
  50.     procedure Button1MouseUp(Sender: TObject; Button: TMouseButton;
  51.       Shift: TShiftState; X, Y: Integer);
  52.   private
  53.     { Private declarations }
  54.   public
  55.     { Public declarations }
  56.   end;
  57.  
  58. var
  59.   Form1: TForm1;
  60.  
  61. implementation
  62.  
  63. {$R *.DFM}
  64.  
  65. procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
  66.   Shift: TShiftState; X, Y: Integer);
  67. const
  68.   SC_DragMove = $F012;  { a magic number }
  69. begin
  70.   ReleaseCapture;
  71.   button1.perform(WM_SysCommand, SC_DragMove, 0);
  72. end;
  73.  
  74. procedure TForm1.Button1Click(Sender: TObject);
  75. begin
  76.   ShowMessage( 'MouseClick!');
  77. end;
  78.  
  79. procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
  80.   Shift: TShiftState; X, Y: Integer);
  81. begin
  82.   ShowMessage( 'MouseUp' );
  83. end;
  84.  
  85. end.
  86.