How can I Change the shape of Firemonkey windows?
In VCL I can change the shape of a form using SetWindowRgn. I would like to do the same with a FireMonkey App when it is on the Windows platform. I would also like to do it on macOS as well, but that may be asking a bit much.
The code I tried compiles, but has no discernible effect:
procedure TfrmMain.FormCreate(Sender: TObject); {$IFDEF MSWINDOWS} var regn: HRGN; {$ENDIF} begin {$IFDEF MSWINDOWS} regn := CreateRoundRectRgn(0, 0, ClientWidth, ClientHeight, 40, 40); SetWindowRgn(WindowHandleToPlatform(Self.Handle).Wnd, regn, True); {$ENDIF} end;
Note that I have already turned the borders off with BorderStyle = None in the Object Inspector.
Is there another way of shaping forms in FireMonkey? Could the other controls on the form (e.g. a toolbar) interfere with the rounded corners.
-
Accepted Answer
0Update: The good the bad and the ugly.
Forms have a Transparency property. When I turned this on, the form became transparent - good!
Now all I have to do is add a shape on the form.
Unfortunately with transparency also comes intangibility. Now the form does not accept mouse clicks - bad!
Strangely when I turn off hit tests on the shape (rectangle), now the form accepts mouse clicks again through the rectangle - this fixes my problem, but it is an extremely ugly way to get this functionality!
This is one to keep for later. Once you know this trick a LOT of new options become really easy to implement.
-
Accepted Answer
0Patrick,
I understand what you meant by styling the background, however I am not sure what you mean by a layer for the region. Are you referring to one of the *Layer3D controls?
I have currently implemented the change on backgroundstyle of the style I am using, setting the corner type to Round, the xradius and yradius to 5, and also tried ClipChildren = True, ClipParent = True for good measure. The result is that the background is shaped correctly, but in the corners there is still black, like there is an underlying style for the form.
-
Accepted Answer
0Hi
Did you try with a style "background" for the visual effect and a layer for the region ? It would work for Mac & Windows without code.