Hallo,
weiß jemand, wie man ein (nicht-MDI) Formular frm über einem MDI-Fenster zentriert?
frm.Position=poOwnerFormCenter funktioniert mit MDI-Fenstern nicht richtig, genausowenig wie meine selbstgeschriebene Prozedur "CenterForm". Ich müsste wissen, wie ich ich die auf den Screen bezogenen Koordinaten des MDI-Fensters erhalte.
<PRE>
procedure CenterForm(frm,parent:TForm);
// Zentriert das Formular "frm" im Formular "parent".
var
P : TPoint;
R : TRect;
begin
if Assigned(frm) and Assigned(parent) then begin
SystemParametersInfo(SPI_GETWORKAREA, 0, @R, 0);
// R = Screen ohne Start-Leiste
if (frm.Width>R.Right-R.Left) or (frm.Height>R.Bottom-R.Top) then
raise Exception.CreateFmt(SFormTooBig, [frm.Name]);
frm.Position := poDesigned;
P.X := Parent.Left + (Parent.Width - frm.Width) div 2;
P.Y := Parent.Top + (Parent.Height - frm.Height) div 2;
// if Parent.FormStyle=fsMDIChild then P := Parent.ClientToScreen(P);
// das geht so nicht!
frm.Left := P.X;
frm.Top := P.Y;
if frm.Left<R.Left
then frm.Left := R.Left;
if frm.Left+frm.Width > R.Right
then frm.Left := R.Right - frm.Width;
if frm.Top<R.Top
then frm.Top := R.Top;
if frm.Top+frm.Height > R.Bottom
then frm.Top := R.bottom - frm.Height;
end;
end;
</PRE>
Gruß, Werner
weiß jemand, wie man ein (nicht-MDI) Formular frm über einem MDI-Fenster zentriert?
frm.Position=poOwnerFormCenter funktioniert mit MDI-Fenstern nicht richtig, genausowenig wie meine selbstgeschriebene Prozedur "CenterForm". Ich müsste wissen, wie ich ich die auf den Screen bezogenen Koordinaten des MDI-Fensters erhalte.
<PRE>
procedure CenterForm(frm,parent:TForm);
// Zentriert das Formular "frm" im Formular "parent".
var
P : TPoint;
R : TRect;
begin
if Assigned(frm) and Assigned(parent) then begin
SystemParametersInfo(SPI_GETWORKAREA, 0, @R, 0);
// R = Screen ohne Start-Leiste
if (frm.Width>R.Right-R.Left) or (frm.Height>R.Bottom-R.Top) then
raise Exception.CreateFmt(SFormTooBig, [frm.Name]);
frm.Position := poDesigned;
P.X := Parent.Left + (Parent.Width - frm.Width) div 2;
P.Y := Parent.Top + (Parent.Height - frm.Height) div 2;
// if Parent.FormStyle=fsMDIChild then P := Parent.ClientToScreen(P);
// das geht so nicht!
frm.Left := P.X;
frm.Top := P.Y;
if frm.Left<R.Left
then frm.Left := R.Left;
if frm.Left+frm.Width > R.Right
then frm.Left := R.Right - frm.Width;
if frm.Top<R.Top
then frm.Top := R.Top;
if frm.Top+frm.Height > R.Bottom
then frm.Top := R.bottom - frm.Height;
end;
end;
</PRE>
Gruß, Werner
Comment