Author: Boris Benjamin Wittfoth
How is it possiple to move an control over the form ?
Answer:
It's very simple - so don't try to write hundreds of lines to solve this problem
Just take a look at this small source-snip
All what we need to do is to override the dynamic MouseDown method of the
TControl-BaseClass and fire an WM_SysCommand event with the magicKey $F012.
I hope this article is helpful for you
1
2 {-----------------------------------------------------------------------------
3
4 hEaDRoOm Development
5 29.10.2002
6
7 Unit Name: HREdit
8 Author: Benjamin Benjamin Wittfoth
9 Purpose:
10 History:
11 -----------------------------------------------------------------------------}
12 unit HREdit;
13
14 interface
15
16 uses
17 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
18 StdCtrls;
19
20 type
21 THREdit = class(TEdit)
22 private
23 fDragable: Boolean;
24 protected
25 procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
26 override;
27 public
28 constructor Create(AOwner: TComponent); override;
29 destructor Destroy; override;
30 published
31 property Dragable: Boolean read fDragable write fDragable;
32 end;
33
34 procedure register;
35
36 implementation
37
38 procedure register;
39 begin
40 RegisterComponents('HEADROOM DEVELOPMENT', [THREdit]);
41 end;
42
43 { THREdit }
44
45 constructor THREdit.Create(AOwner: TComponent);
46 begin
47 inherited Create(AOwner);
48 end;
49
50 destructor THREdit.Destroy;
51 begin
52 inherited;
53 end;
54
55 procedure THREdit.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
56 Y: Integer);
57 const
58 SC_DragMove = $F012; // important key !!
59 begin
60 inherited;
61 if assigned(onMouseDown) then
62 OnMouseDown(self, Button, Shift, x, y);
63 if fDragable then
64 begin
65 ReleaseCapture;
66 (self as TControl).perform(WM_SysCommand, SC_DragMove, 0); // this is the key !
67 end;
68 end;
69
70 end.
71
72 if you put then next line after ReleaseCapture; the object will even come to the
73 front before moving it and not just after.
74
75 (self as TControl).BringToFront;
76
77 Cordinates of control. Simply use an Timer on your form - i know this is not
78 elegant, but it works.
79
80 procedure TForm1.TimerTimer(Sender: TObject);
81 begin
82 Edit1.text := inttostr(Edit1.Left) + '/' + inttostr(Edit1.top);
83 end;
|