Thread View: comp.lang.pascal.delphi.components.usage
6 messages
6 total messages
Started by Zimba
Tue, 17 Nov 1998 00:00
Moving components around
Author: Zimba
Date: Tue, 17 Nov 1998 00:00
Date: Tue, 17 Nov 1998 00:00
41 lines
2321 bytes
2321 bytes
please I want to be able create components at runtime as my codes below
show but I would like to be able to move them to desired positions. Does
anyone know how I can move them around? Right now I can only create them
with the codes below below I cannot move them around.
Zimba
procedure TOutputForm.FormMouseDown (
Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
MyClass: TComponentClass;
MyComp: TComponent;
begin
MyClass := TComponentClass (
GetClass (MainForm.ComboBox1.Text));
if MyClass = nil then
Beep
else
begin
MyComp := MyClass.Create (self);
MyComp.Name := MainForm.GetNextName (MyClass);
if MyClass.InheritsFrom (TControl) then
begin
TControl (MyComp).Left := X;
TControl (MyComp).Top := Y;
TControl (MyComp).Parent := self;
end;
end;
MainForm.UpdateList;
end;
--
*****************************************************************
*PLEASE, TO SEND ME AN E-MAIL REMOVE "REMOVE" FROM MY ADDRESS. *
* *
* *
*****************************************************************
Re: Moving components around
Author: Stephen Beckett
Date: Tue, 17 Nov 1998 00:00
Date: Tue, 17 Nov 1998 00:00
4 lines
1396 bytes
1396 bytes
Couldn't you just update a selected component's x,y properties on the mouse down as long as you had prevoiusly selected a component, maybe by looping through a form's component list and comparing the mouse location with the rect formed by each component's x,y and height,width?
Re: Moving components around
Author: Mark Timmings
Date: Tue, 17 Nov 1998 00:00
Date: Tue, 17 Nov 1998 00:00
20 lines
2203 bytes
2203 bytes
In article <36507ECC.2BD4BC5E@bellsouth.net>, Zimba <REMOVEkennaa@bellsouth.net> writes >please I want to be able create components at runtime as my codes below >show but I would like to be able to move them to desired positions. Does >anyone know how I can move them around? Right now I can only create them >with the codes below below I cannot move them around. [snip] There are a couple of ways of doing this. The first is you intercept the mousedown, mouseup and mousemove events of the components you've created and then either draw the rubber banding or draw the new positions (and/or size) as the component is dragged (depending upon the effect you want). Alternatively, check out Torry's or the Delphi Super Page web sites for components to do this for you. I know of a couple, one is called TStretchHandles (or Handles) and it saves you a lot of time and effort and can do everything you probably want. I hope this helps Mark
Re: Moving components around
Author: Guido Geurts
Date: Wed, 18 Nov 1998 00:00
Date: Wed, 18 Nov 1998 00:00
98 lines
4104 bytes
4104 bytes
Here is the long way, there is a very short way by sending a "magic number"
to it, but I forgot. If I find it again, I will post it.
TForm1 = class(TForm)
Button1: TButton;
procedure Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Button1MouseUp(Sender: TObject; Button:
TMouseButton; Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
MouseDownSpot : TPoint;
Capturing : bool;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if ssCtrl in Shift then begin
SetCapture(Button1.Handle);
Capturing := true;
MouseDownSpot.X := x;
MouseDownSpot.Y := Y;
end;
end;
procedure TForm1.Button1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
if Capturing then begin
Button1.Left := Button1.Left - (MouseDownSpot.x - x);
Button1.Top := Button1.Top - (MouseDownSpot.y - y);
end;
end;
procedure TForm1.Button1MouseUp(Sender: TObject; Button:
TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Capturing then begin
ReleaseCapture;
Capturing := false;
Button1.Left := Button1.Left - (MouseDownSpot.x - x);
Button1.Top := Button1.Top - (MouseDownSpot.y - y);
end;
end;
Zimba schreef:
> please I want to be able create components at runtime as my codes below
> show but I would like to be able to move them to desired positions. Does
> anyone know how I can move them around? Right now I can only create them
> with the codes below below I cannot move them around.
>
> Zimba
>
> procedure TOutputForm.FormMouseDown (
> Sender: TObject; Button: TMouseButton;
> Shift: TShiftState; X, Y: Integer);
> var
> MyClass: TComponentClass;
> MyComp: TComponent;
> begin
> MyClass := TComponentClass (
> GetClass (MainForm.ComboBox1.Text));
> if MyClass = nil then
> Beep
> else
> begin
> MyComp := MyClass.Create (self);
> MyComp.Name := MainForm.GetNextName (MyClass);
> if MyClass.InheritsFrom (TControl) then
> begin
> TControl (MyComp).Left := X;
> TControl (MyComp).Top := Y;
> TControl (MyComp).Parent := self;
> end;
> end;
> MainForm.UpdateList;
> end;
>
> --
>
> *****************************************************************
> *PLEASE, TO SEND ME AN E-MAIL REMOVE "REMOVE" FROM MY ADDRESS. *
> * *
> * *
> *****************************************************************
Re: Moving components around
Author: S๏ฟฝbastien Daupleix
Date: Thu, 19 Nov 1998 00:00
Date: Thu, 19 Nov 1998 00:00
11 lines
1598 bytes
1598 bytes
Just include in the MouseMove event of each of the component you
want to move the two following magic lines :
ReleaseCapture;
perform(WM_SysCommand, $F012, 0);
(have found it on the net, no credit for me...)
Sebastien Daupleix
altis Consultant
altis@bigfoot.com
Re: Moving components around
Author: Guido Geurts
Date: Thu, 19 Nov 1998 00:00
Date: Thu, 19 Nov 1998 00:00
21 lines
1806 bytes
1806 bytes
Here is the short way to do this
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;
Zimba schreef:
> please I want to be able create components at runtime as my codes below
> show but I would like to be able to move them to desired positions. Does
> anyone know how I can move them around? Right now I can only create them
> with the codes below below I cannot move them around.
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads