2010-07-21 3 views
2

부모 대화 상자에 예외 대화 상자를 포함하여 모든 메시지 대화 상자를 가운데에 놓으려고합니다. 항상 화면 가운데에 나타나지 않게해야합니다.Delphi에서 Windows Exception 대화 상자를 중앙화하는 방법은 무엇입니까?

저는 MessageDlgPos를 사용하면 X와 Y의 매개 변수가 대화 상자를 찾을 수 있으며 사용자에게 표시하려는 모든 메시지를 처리 ​​할 수 ​​있다는 점에 유의하십시오. 그러나 예외 대화 상자의 위치는 어떻습니까? 부모 양식의 중심에 나타날 수 있습니까?

도움을 주시면 큰 도움이됩니다.

답변

1

@Rucia, 제 제안은 TApplicationEvents 구성 요소의 OnException 이벤트를 사용하고 CreateMessageDialog 기능을 사용하여 고유 한 대화 상자를 만드는 것입니다.

이 샘플을 참조하십시오.

procedure TForm1.ApplicationEvents1Exception(Sender: TObject; E: Exception); 
var 
    MyDialogMsg : TForm; 
    ALeft  : Integer; 
    ATop  : Integer; 

begin 
    //Create the dialog with the exeception message 
    MyDialogMsg := CreateMessageDialog(E.Message, mtError, [mbOk]); 
    try 
     //Calculate the pos of the dialog using the Screen.ActiveForm and the dialog size. 
     ALeft := Screen.ActiveForm.Left + (Screen.ActiveForm.Width div 2) - (MyDialogMsg.Width div 2); 
     ATop := Screen.ActiveForm.Top + (Screen.ActiveForm.Height div 2) - (MyDialogMsg.Height div 2); 
     if ALeft < 0 then ALeft := Screen.ActiveForm.Left; 
     if ATop < 0 then ATop := Screen.ActiveForm.Top; 
     if (ALeft + MyDialogMsg.Width > Screen.Width) or (ATop + MyDialogMsg.Height > Screen.Height) 
     then 
     begin 
      ALeft := (Screen.Width - MyDialogMsg.Width) div 2; 
      ATop := (Screen.Height - MyDialogMsg.Height) div 2; 
      MyDialogMsg.SetBounds (ALeft, ATop, MyDialogMsg.Width, MyDialogMsg.Height); 
     end 
     else 
     MyDialogMsg.SetBounds(ALeft, ATop, MyDialogMsg.Width, MyDialogMsg.Height); 
     //show the dialog 
     MyDialogMsg.ShowModal; 
    finally 
    MyDialogMsg.Free; 
    end; 
end; 
+0

대단히 감사합니다. 저건 완벽 해! – Rucia

관련 문제