Recent

Author Topic: Use TPanel to move Window? Anything like Form Magnet (move one they all move)?  (Read 639 times)

ozznixon

  • Full Member
  • ***
  • Posts: 119
    • http://www.modernpascal.com/
Hello,
   I am in the process of porting some of our component demonstrations from Delphi to Lazarus - mainly Mac OSX and Linux. The demos use a TPanel aligned to alTop - and hook to windows to drag the whole form. Is this even possible on Mac and/or Linux?
   I also built the demos back in WinAMP days - so the two sibling TForms are 'magnetically attached' to the main TForm - so move one, they all move. Or pull Form2 or Form3 away from Form1 then they respond independently. Get near each other, they "snap" to one of the 4 corners of Form1 - and now work in unison. Is this even possible on Mac and/or Linux?
Thanks for any insight!Ozz
---
Want to kick the tires to a Free Pascal like script engine? http://www.ModernPascal.com/

balazsszekely

  • Guest
@ozznixon

Quote
I am in the process of porting some of our component demonstrations from Delphi to Lazarus - mainly Mac OSX and Linux. The demos use a TPanel aligned to alTop - and hook to windows to drag the whole form. Is this even possible on Mac and/or Linux?
Try this, should work both on Linux and Mac(not tested):
Code: Pascal  [Select][+][-]
  1. type
  2.   TForm1 = class(TForm)
  3.     Panel1: TPanel;
  4.     procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  5.     procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer );
  6.     procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  7.   private
  8.     FX, FY: Integer;
  9.   public
  10.   end;
  11.  
  12. //...
  13.  
  14. procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  15.   Shift: TShiftState; X, Y: Integer);
  16. begin
  17.   FX := X;
  18.   FY := Y;
  19.   Screen.Cursor := crHandPoint;
  20. end;
  21.  
  22. procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  23.   Y: Integer);
  24. begin
  25.   if Form1.WindowState = wsMaximized then
  26.     Exit;
  27.   if ssLeft in Shift then
  28.   begin
  29.     Form1.Left := Form1.Left + (X - FX);
  30.     Form1.Top := Form1.Top + (Y - FY);
  31.   end;
  32. end;
  33.  
  34. procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  35.   Shift: TShiftState; X, Y: Integer);
  36. begin
  37.   Screen.Cursor := crDefault;
  38. end;  
  39.  


Quote
I also built the demos back in WinAMP days - so the two sibling TForms are 'magnetically attached' to the main TForm - so move one, they all move. Or pull Form2 or Form3 away from Form1 then they respond independently. Get near each other, they "snap" to one of the 4 corners of Form1 - and now work in unison. Is this even possible on Mac and/or Linux?
Shouldn't be too difficult to implement. You need a few more if then.

 

TinyPortal © 2005-2018