Jump to content
Mike Warren

Placing Child Behind Parent

Recommended Posts

Is it possible to make a child FMX component display behind the parent?

SendToBack only affects its Z-order in relation to other siblings.

 

Share this post


Link to post
12 minutes ago, Mike Warren said:

Is it possible to make a child FMX component display behind the parent?

Of course not.  VCL does not support that either.  Why would you ever want a child to go behind its parent?

Share this post


Link to post

Thanks for your reply Remy,

 

I suspected that might be the case.

 

Why do I want to do this?

 

I have a component I create at runtime that's inherited from TRectangle. One of the additions is that I have a TImage to create an associated "icon" that sits next to the rectangle. These 2 items are normally moved together, but can be moved independently by holding the control key down. If the user decided to overlap these 2 components, then showing the complete rectangle is more desirable.

 

I can't make the parent the image, because that will sometimes be hidden, which would hide the rectangle, which must always be visible.

 

Edited by Mike Warren

Share this post


Link to post
15 minutes ago, Mike Warren said:

I have a component I create at runtime that's inherited from TRectangle. One of the additions is that I have a TImage to create an associated "icon" that sits next to the rectangle. These 2 items are normally moved together, but can be moved independently by holding the control key down. If the user decided to overlap these 2 components, then showing the complete rectangle is more desirable.

 

I can't make the parent the image, because that will sometimes be hidden, which would hide the rectangle, which must always be visible.

OK, so then simply make the TRectangle be the Owner of the TImage, but make the TRectangle and TImage be siblings of the same parent, instead of making the TRectangle be the parent of the TImage.  This way, the TImage can go behind the TRectangle, and you can move the TImage whenever the TRectangle is moved and vice versa, unless the Ctrl key is down.

 

This is exactly how VCL controls like TLabeledEdit are implemented, for example.

  • Like 1

Share this post


Link to post

That's what I'm going to have to do. It just means I'll have to manually move the TImage whenever the TRectangle is moved.

 

Thanks.

 

Share this post


Link to post
9 minutes ago, Mike Warren said:

That's what I'm going to have to do. It just means I'll have to manually move the TImage whenever the TRectangle is moved.

Yes, but that is not a big deal at all.

Share this post


Link to post

@Mike Warren

 

what about this idea...

  • 1 TLayout (or any other container to Image/Rectangle) = HitTest = TRUE!
    • then you can use Layout client-area to expand your rectangle and no needs to do nothing in Timage... doubleclick on rectangle to expand for all client-area from TLayout/container
...
  private
    FMouseMoving                : boolean;
    FControlMouseClickPositionXY: TPointF;
    FRectangleSizeDefault       : TRectF;
  public
...
implementation

{$R *.fmx}
{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  FRectangleSizeDefault := Rectangle1.BoundsRect;
end;

procedure TForm1.Layout1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
  FControlMouseClickPositionXY := PointF(X, Y);
  TControl(Sender).AutoCapture := true;
  FMouseMoving                 := true;
end;

procedure TForm1.Layout1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
  TControl(Sender).AutoCapture := false;
  FMouseMoving                 := false;
end;

procedure TForm1.Layout1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
var
  XY: TPointF;
begin
  if FMouseMoving then
    begin
      XY                          := TControl(Sender).LocalToAbsolute(PointF(X - FControlMouseClickPositionXY.X, Y - FControlMouseClickPositionXY.Y));
      TControl(Sender).Position.X := XY.X;
      TControl(Sender).Position.Y := XY.Y;
    end;
end;

procedure TForm1.Rectangle1DblClick(Sender: TObject);
begin
  if (Rectangle1.Align = TAlignLayout.Client) then
    begin
      Rectangle1.Align      := TAlignLayout.Right;
      Rectangle1.BoundsRect := FRectangleSizeDefault;
    end
  else
    Rectangle1.Align := TAlignLayout.Client;
end;

end.

 

 

bds_tgWUVn66ou.gif   image.thumb.png.4ad5e288106cd5ebe0c3bf5320e1c698.png

Edited by programmerdelphi2k

Share this post


Link to post

Thanks for the suggestion, but it's not what I'm after. Remy's solution is best for my situation.

 

MoveComponent.gif.0c9a02937bf1027a8790c870fd381c84.gif

Share this post


Link to post
22 minutes ago, Mike Warren said:

but it's not what I'm after.

no problem... dont forget that you can move the elements beyond the containers ( negative or positive positions), background or foreground

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

×