Jump to content
Sign in to follow this  
Drummer1972

Doubts about THorzScrollBox operation

Recommended Posts

 

I have one THorzScrollBox with three TGridLayouts (c++ Builder 11):


 

 

¿Can I move it around with the mouse (ShowScrollBars=false)?

 

Any ideas.. THANKS

 

 

ejemplo.png

Edited by Drummer1972

Share this post


Link to post

hi @Drummer1972

 

here a Guitarman +/-  :classic_biggrin:

 

try some like this:  my sample is in Delphi ... sorry Im not CBuilder !

 

type
  TForm1 = class(TForm)
    HorzScrollBox1: THorzScrollBox;
    rectGreen: TRectangle;
    rectRed: TRectangle;
    rectBlue: TRectangle;
    Memo1: TMemo;
    rectOrchid: TRectangle;
    procedure HorzScrollBox1DragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Operation: TDragOperation);
    procedure HorzScrollBox1DragDrop(Sender: TObject; const Data: TDragObject; const Point: TPointF);
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

type
  TArrRectangles = TArray<TRectangle>;

var
  LArrRectangles: TArrRectangles;

procedure TForm1.FormCreate(Sender: TObject);
var
  j         : single;
  LText     : string;
  LRectangle: TRectangle;
begin
  LArrRectangles := [];
  //
  j := 0;
  //
  for var X: integer := 0 to (HorzScrollBox1.Content.ChildrenCount - 1) do
    if (HorzScrollBox1.Content.Children.Items[X] is TRectangle) then // rectangles in HorzScrollBox1
      begin
        LRectangle              := TRectangle(HorzScrollBox1.Content.Children.Items[X]);
        LRectangle.Margins.Left := 5; // space to working with Drag...Drop it!
        LRectangle.DragMode     := TDragMode.dmAutomatic;
        LRectangle.Tag          := X;        
        LRectangle.Position.X   := j;
        LRectangle.Align        := TAlignLayout.Left; // all to left...
        LArrRectangles          := LArrRectangles + [LRectangle];
        j                       := j + LRectangle.Width + 1; // next rectangle position 
        LText                   := LText + LRectangle.Name + ' ' + LRectangle.Position.X.ToString + ' ' + LRectangle.Tag.ToString + slinebreak;
      end;
  //
  Memo1.Lines.Add(LText);
  //
  if (length(LArrRectangles) > 0) then // else there is no rectangles on HorzScrollBolx1
    HorzScrollBox1.DragMode := TDragMode.dmAutomatic;
end;

procedure TForm1.HorzScrollBox1DragDrop(Sender: TObject; const Data: TDragObject; const Point: TPointF);
begin
  if (Data.Source is TRectangle) then
    LArrRectangles[TRectangle(Data.Source).Tag].Position.X := Application.MainForm.ScreenToClient(Screen.MousePos).X; // rect in new position...
end;

procedure TForm1.HorzScrollBox1DragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Operation: TDragOperation);
begin
  if (Data.Source is TRectangle) then
    Operation := TDragOperation.Move;
end;

end.

 

Project1_4ITalSldre.gif

Edited by programmerdelphi2k

Share this post


Link to post
12 hours ago, Drummer1972 said:


Thank you very much for your time, it was just what I was looking for... you are a crack "Guitarman" 
 

 

 

Edited by Drummer1972

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×