Mike Warren 2 Posted July 8, 2023 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
Remy Lebeau 1397 Posted July 8, 2023 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
Mike Warren 2 Posted July 8, 2023 (edited) 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 July 8, 2023 by Mike Warren Share this post Link to post
Remy Lebeau 1397 Posted July 9, 2023 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. 1 Share this post Link to post
Mike Warren 2 Posted July 9, 2023 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
Remy Lebeau 1397 Posted July 9, 2023 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
programmerdelphi2k 237 Posted July 9, 2023 (edited) @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. Edited July 9, 2023 by programmerdelphi2k Share this post Link to post
Mike Warren 2 Posted July 9, 2023 Thanks for the suggestion, but it's not what I'm after. Remy's solution is best for my situation. Share this post Link to post
programmerdelphi2k 237 Posted July 9, 2023 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