Recent

Author Topic: Select and move multi Element ?  (Read 616 times)

majid.ebru

  • Hero Member
  • *****
  • Posts: 519
Select and move multi Element ?
« on: June 22, 2024, 06:52:51 am »
Hi
please help and guide me ?
i use this code for select panel with Shift key and move it .
how can i select and move multi panel ?
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls ,Types;
  9.  
  10. type
  11.  
  12.         { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.                 Panel1: TPanel;
  16.                 Panel2: TPanel;
  17.                 procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  18.                         Shift: TShiftState; X, Y: Integer);
  19.                 procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
  20.                         );
  21.                 procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  22.                         Shift: TShiftState; X, Y: Integer);
  23.   private
  24.  
  25.   public
  26.  
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.         FDownX ,FDownY ,FDragging: Integer;
  32.  
  33. implementation
  34.  
  35. {$R *.lfm}
  36.  
  37. { TForm1 }
  38.  
  39. procedure High_light_Control(aControl: TPanel);
  40. var
  41.         r: types.TRect;
  42.         aCC: TControlCanvas;
  43. begin
  44.   if(Assigned(aControl))then begin
  45.                 R := aControl.BoundsRect;
  46.           InflateRect(r,3,3);
  47.           aCC := Tcontrolcanvas.Create;
  48.           acc.Control:= aControl.Parent;
  49.           with acc do begin
  50.             Pen.color := clGreen;
  51.             Pen.Width := 3;
  52.             Pen.Style := psDash;
  53.             Brush.Style:= bsClear;
  54.             rectangle(r);
  55.           end;
  56.           acc.free;
  57.         end;
  58. end;
  59.  
  60. procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  61.         Shift: TShiftState; X, Y: Integer);
  62. begin
  63.   if(ssShift in Shift)then
  64.     High_light_Control(Sender as TPanel)
  65.   else begin
  66.                 FDownX := X;
  67.                 FDownY := Y;
  68.                 FDragging := 2;
  69.         end;
  70. end;
  71.  
  72. procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  73.         Y: Integer);
  74. begin
  75.   if 2 = FDragging then
  76.           with(Sender as TPanel) as TPanel do begin
  77.             Left := X - FDownX + Left;
  78.             Top  := Y - FDownY + Top;
  79.           end;
  80. end;
  81.  
  82. procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  83.         Shift: TShiftState; X, Y: Integer);
  84. begin  
  85.   if 2 = FDragging then begin
  86.                 Invalidate;
  87.                 FDragging := 0;
  88.         end;
  89. end;
  90.  
  91. end.
  92.  

jamie

  • Hero Member
  • *****
  • Posts: 6734
Re: Select and move multi Element ?
« Reply #1 on: June 22, 2024, 06:19:28 pm »
You have couple of options here, use an overlayed transparent window that encompasses the panels and that way this window will receive the events for anything under it.

 Or you can use a Tag flag of sorts to mark the panel in the moving state and then perform the mouse moves while monitor the mouse actions in the OnUserInput event of the TApplication instance.
 
 With that, you can determine which object is moving the mouse etc. and then check the flags within the panel to see if one or more need moving.

 Most people tag the controls to be moved and then activate another control on top that could be like transparent as the moving tool.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018