here, my sample how to do it:
RAD Studio 10.3.3 Arch (Rio)
VCL project for test
none any Windows API is used (at least directly)
the magic:
TransparentColor on Forms!
Calculate the position where is the first "Shape" and how use it in SecondForm position!
FormMain or any other:
unit uFormMain;
interface
uses
... all units necessary below
type
TfrmFormMain = class(TForm)
Shape1: TShape; // ======== Color = YELLOW
Button1: TButton;
Shape2: TShape;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
end;
var
frmFormMain: TfrmFormMain;
//
X1frmFormMainShapeLeft: integer = 0;
Y1frmFormMainShapeTop : integer = 0;
implementation
{$R *.dfm}
uses
uFormSecond;
procedure TfrmFormMain.Button1Click(Sender: TObject);
var
lMyOffsetTop : integer;
lMyOffsetLeft: integer;
begin
// here, my values arbitrary...
lMyOffsetTop := 8; // you need calculate the margin vertical values ( area-non-client )
lMyOffsetLeft := 8; // calculate the margin horizontal values( area-non-client )
//
Y1frmFormMainShapeTop := ClientToScreen(TPoint.Create(0, 0)).Y + Shape1.Top - (Self.Height - Self.ClientHeight) + lMyOffsetTop;
X1frmFormMainShapeLeft := ClientToScreen(TPoint.Create(0, 0)).X + Shape1.Left - (Self.Width - Self.ClientWidth) + lMyOffsetLeft;
//
frmFormSecond := TfrmFormSecond.Create(nil);
try
frmFormSecond.ShowModal;
finally
frmFormSecond.Free;
end;
end;
procedure TfrmFormMain.FormCreate(Sender: TObject);
begin
// Self.AlphaBlendValue := 180; // 0 = total transparence ... 255 = non-transparence
// Self.AlphaBlend := true; // active transparence on form?
Self.TransparentColorValue := clYellow;
Self.TransparentColor := true; //
end;
initialization
ReportMemoryLeaksOnShutdown := true;
finalization
end.
SecondForm or any other:
unit uFormSecond;
interface
uses
... // all units necessary below
type
TfrmFormSecond = class(TForm)
Shape1: TShape; // ======= Color = Blue
procedure FormCreate(Sender: TObject);
private
public
end;
var
frmFormSecond: TfrmFormSecond;
implementation
{$R *.dfm}
uses
uFormMain;
procedure TfrmFormSecond.FormCreate(Sender: TObject);
begin
// Self.AlphaBlendValue := 180; // 0 = total transparence ... 255 = non-transparence
// Self.AlphaBlend := true; // active transparence on form?
Self.TransparentColorValue := clBlue;
Self.TransparentColor := true; //
//
Self.Left := X1frmFormMainShapeLeft - Shape1.Left;
Self.Top := Y1frmFormMainShapeTop - Shape1.Top;
end;
end.
hug