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

50 Visitors Online


 
...move window controls at runtime?
Autor: Peter Morris
Homepage: http://www.sandbrooksoftware.com/DPSC/Tips/PeterMorris/
[ Print tip ]  

Tip Rating (9):  
     


{Assign the OnMouseDown event for each component you want to move at runtime }


type
  
TForm1 = class(TForm)
    {...}
    
procedure MoveControl(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    
{ Private-Declarations }
  
public
    
{ Public-Declarations }
  
end;
end;



// In the implementation Section:


procedure TForm1.MoveControl(Sender:TObject; Button:TMouseButton;
          Shift:TShiftState; X,Y:Integer);
var
  
TempPanel: TPanel;
  Control: TControl;
begin
  
// Releases the mouse capture from a window
  
ReleaseCapture;
  // If the component is a TWinControl, move it directly
  
if Sender is TWinControl then
    
TWinControl(Sender).Perform(WM_SYSCOMMAND,$F012,0)
  else
  try
    
Control := TControl(Sender);
    TempPanel := TPanel.Create(Self);
    with TempPanel do
    begin
      
//Replace the component with TempPanel
      
Caption := '';
      BevelOuter := bvNone;
      SetBounds(Control.Left, Control.Top, Control.Width, Control.Height);
      Parent := Control.Parent;
      //Put our control in TempPanel
      
Control.Parent := TempPanel;
      //Move TempPanel with control inside it
      
Perform(WM_SYSCOMMAND, $F012, 0);
      //Put the component where the panel was dropped
      
Control.Parent := Parent;
      Control.Left := Left;
      Control.Top := Top;
    end;
  finally
    
TempPanel.Free;
  end;
end;





 

Rate this tip:

poor
very good


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