Thema: Delphi MessageBox Postion

Einzelnen Beitrag anzeigen

Benutzerbild von Dani
Dani

Registriert seit: 19. Jan 2003
732 Beiträge
 
Turbo Delphi für Win32
 
#9

Re: MessageBox Postion

  Alt 25. Feb 2008, 22:03
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
  Mit Zitat antworten Zitat