🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.delphi.components.usage
Article #16

Re: Moving components around

#16
From: Guido Geurts
Date: Wed, 18 Nov 1998 00:00
98 lines
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.  *
> *                                                               *
> *      *
> *****************************************************************
Technical Details
Message-ID: <36534997.45F7F5DA@village.uunet.be>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36507ECC.2BD4BC5E@bellsouth.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 108890,ad7d8cb1fb4c02ee
X-Google-Attributes: gid108890,public
X-Google-Thread: fb0ea,ad7d8cb1fb4c02ee
X-Google-Attributes: gidfb0ea,public
X-Google-Thread: 112b07,ad7d8cb1fb4c02ee
X-Google-Attributes: gid112b07,public
X-Google-Thread: f973b,ad7d8cb1fb4c02ee
X-Google-Attributes: gidf973b,public
X-Google-Thread: fe2ce,ad7d8cb1fb4c02ee
X-Google-Attributes: gidfe2ce,public
X-Google-Thread: 109d99,ad7d8cb1fb4c02ee
X-Google-Attributes: gid109d99,public
From: Guido Geurts <GuidoG@village.uunet.be>
Subject: Re: Moving components around
Date: 1998/11/18
Message-ID: <36534997.45F7F5DA@village.uunet.be>
X-Deja-AN: 413294843
Content-Transfer-Encoding: 7bit
References: <36507ECC.2BD4BC5E@bellsouth.net>
To: Zimba <REMOVEkennaa@bellsouth.net>
Content-Type: text/plain; charset=us-ascii
Organization: UUNET Benelux (post does not reflect views of UUNET Benelux)
Mime-Version: 1.0
Newsgroups: comp.lang.pascal.delphi.components.usage,comp.lang.pascal.delphi.components.writing,comp.lang.pascal.delphi.components.misc,comp.lang.pascal.delphi.components,borland.public.delphi.vcl.components.using,borland.public.delphi.vcl.components.writing