whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

46 Visitors Online


 
...move components at Runtime?
Autor: Thomas Stutz
[ Print tip ]  


Tip Rating (62):  
     


{
  This example shows how to move components at runtime, dragging it.
  You are able to see the components move as you drag them.
  Attach the Control event handlers (ControlMouseDown,...)
  to all components you want to move.

  Dieses Beispiel zeigt, wie man Komponenten zur Laufzeit
  verschieben kann. Während dem Verschieben werden die
  Komponenten voll angezeigt.
  An alle Komponenten, welche verschoben werden sollen,
  die Eregnisse ControlMouseDown,ControlMouseMove und
  ControlMouseUp zuweisen.
}


type
  
TForm1 = class(TForm)
    Image1: TImage;
    procedure ControlMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure ControlMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure ControlMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    
{ Private declarations }
    
FDownX,
    FDownY: Integer;
    FDragging: Boolean;
  public
    
{ Public declarations }
  
end;

var
  
Form1: TForm1;

implementation

{$R *.DFM}

type
  
TMoveCracker = class(TControl);

procedure TForm1.ControlMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  
FDownX := X;
  FDownY := Y;
  FDragging := True;
  TMoveCracker(Sender).MouseCapture := True;
end;

procedure TForm1.ControlMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if 
FDragging then
    with 
Sender as TControl do
    begin
      
Left := X - FDownX + Left;
      Top  := Y - FDownY + Top;
    end;
end;

procedure TForm1.ControlMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if 
FDragging then
  begin
    
FDragging := False;
    TMoveCracker(Sender).MouseCapture := False;
  end;
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners