Delphi-Quellcode:
function MessageDlgPos2(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; ParentForm: TForm = nil; HelpCtx: Longint = -1;
const HelpFileName: string = ''): Integer;
begin
with CreateMessageDialog(Msg, DlgType, Buttons) do
try
HelpContext := HelpCtx;
HelpFile := HelpFileName;
if Assigned(ParentForm) then begin
Position := poDesigned;
//0 div 2 -> 0, also kein Problem.
Left := ParentForm.Left + ((ParentForm.Width - Width) div 2);
Top := ParentForm.Top + ((ParentForm.Height - Height) div 2);
end else begin
Position := poScreenCenter;
end;
Result := ShowModal;
finally
Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MessageDlgPos2('Dies ist ein Test', mtInformation, [mbOK], Self);
end;
Wäre vielleicht noch ganz gut zu prüfen, ob der Dialog überhaupt auf einem Bildschirm sichtbar ist und ihn dann ggf zu verschieben.
Dani H.
At Least I Can Say I Tried