Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
495 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (5)


Moving Controls over the formGo to Boris Benjamin Wittfoth's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
dragging / moving TWincontrol-Component over an TForm
Product:
Delphi all versions
Category:
Component Writing
Skill Level:
Scoring:
Last Update:
10/21/2004
Search Keys:
delphi delphi3000 article borland vcl code-snippet move drag control controls around over a form Tform Twincontrol
Times Scored:
2
Visits:
3427
Uploader: Boris Benjamin Wittfoth
Company: Currex GmbH
Reference: N/A
 
Question/Problem/Abstract:
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.

best regards

Boris Benjamin Wittfoth



{-----------------------------------------------------------------------------


hEaDRoOm Development
29.10.2002

Unit Name: HREdit
Author:    Benjamin Benjamin Wittfoth
Purpose:
History:
-----------------------------------------------------------------------------}
unit HREdit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  THREdit = class(TEdit)
  private
    fDragable:Boolean;
  protected
    procedure MouseDown(Button: TMouseButton;Shift: TShiftState; X, Y: Integer);override;
  public
    Constructor Create(AOwner:TComponent);override;
    Destructor Destroy;override;
  published
    property Dragable:Boolean read fDragable write fDragable;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('HEADROOM DEVELOPMENT', [THREdit]);
end;

{ THREdit }
constructor THREdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
end;

destructor THREdit.Destroy;
begin
  inherited;
end;

procedure THREdit.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
const
  SC_DragMove = $F012; // important key  !!
begin
  inherited;
  if assigned(onMouseDown)then
    OnMouseDown(self,Button,Shift,x,y);
  if fDragable then
  begin
    ReleaseCapture;
    (self as TControl).perform(WM_SysCommand, SC_DragMove, 0); // this is the key !
  end;
end;

end.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Neat little one
    Tommy Andersen (Nov 5 2002 10:40AM)

Nice article.
If you put then next line after ReleaseCapture; the object will even come to the front before moving it and not just after.

(self as TControl).BringToFront;


Best Regards
Tommy Andersen
EasyWare.org

Respond

Snapgrid and events for the X,Y position during drag.
    Magnus Flysjö (Oct 30 2002 12:11PM)

I once needed this kind of function in an application.

I used this magic key but I never found out how to get the cordinates of the control during the actual move.

Also I needed to move the control against a 8x8 snapgrid.

Anyone with experience in this, using this internal move message?
Respond

RE: Snapgrid and events for the X,Y position during drag.
Boris Benjamin Wittfoth (Oct 30 2002 5:06PM)

Hi Magnus,

Simply use an Timer on your form - i know this is not elegant, but it works.

procedure TForm1.TimerTimer(Sender: TObject);
begin
  Edit1.text:=inttostr(Edit1.Left)+'/'+inttostr(Edit1.top);
end;




Respond

RE: RE: Snapgrid and events for the X,Y position during drag.
Mark (Oct 31 2002 5:55PM)

Hi,

I try to declare a MouseUp like the MouseDown to make a beep every time the mouse button goes up. But only on the right button I get a beep. On the left button nothing happens.

Why

Thanks

Mark
Respond

RE: RE: RE: Snapgrid and events for the X,Y position during drag.
anonymus (Nov 5 2002 11:39AM)

The reason for this is because the WM_SysCommand message with SC_DragMove also calls SetCapture() ... The mouseup event is sent to another control...


Best Regards
Tommy Andersen
EasyWare.org

Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
L. Rosenstein
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)