home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / handson / archive / Issue150 / delphi / BorlandMover / BMoveUnit1.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-12-16  |  1.7 KB  |  73 lines

  1. unit BMoveUnit1;
  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;
  43.  
  44. type
  45.   TForm1 = class(TForm)
  46.     Panel1: TPanel;
  47.     procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  48.       Shift: TShiftState; X, Y: Integer);
  49.   private
  50.     { Private declarations }
  51.   public
  52.     { Public declarations }
  53.   end;
  54.  
  55. var
  56.   Form1: TForm1;
  57.  
  58. implementation
  59.  
  60. {$R *.DFM}
  61.  
  62. procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  63.   Shift: TShiftState; X, Y: Integer);
  64. const
  65.   SC_DragMove = $F012;  { a magic number }
  66. begin
  67.   ReleaseCapture;
  68.   panel1.perform(WM_SysCommand, SC_DragMove, 0);
  69. end;
  70.  
  71.  
  72. end.
  73.