Generic dialog with custom captions for buttons

前端 未结 3 1895
陌清茗
陌清茗 2020-12-30 11:15

I know this issue have been up since before (ex. Best way to show customized message dialogs), but I still don\'t find what I want.

I started like this:



        
3条回答
  •  时光取名叫无心
    2020-12-30 11:56

    you can use this code:

    function MyMessageDlg(CONST Msg: string; DlgTypt: TmsgDlgType; button: TMsgDlgButtons;
      Caption: ARRAY OF string; dlgcaption: string): Integer;
    var
      aMsgdlg: TForm;
      i: Integer;
      Dlgbutton: Tbutton;
      Captionindex: Integer;
    begin
      aMsgdlg := createMessageDialog(Msg, DlgTypt, button);
      aMsgdlg.Caption := dlgcaption;
      aMsgdlg.BiDiMode := bdRightToLeft;
      Captionindex := 0;
      for i := 0 to aMsgdlg.componentcount - 1 Do
      begin
        if (aMsgdlg.components[i] is Tbutton) then
        Begin
          Dlgbutton := Tbutton(aMsgdlg.components[i]);
          if Captionindex <= High(Caption) then
            Dlgbutton.Caption := Caption[Captionindex];
          inc(Captionindex);
        end;
      end;
      Result := aMsgdlg.Showmodal;
    end;
    

    For example:

    MyMessageDlg('Hello World!', mtInformation, [mbYes, mbNo],
          ['Yessss','Noooo'], 'New MessageDlg Box'):
    

提交回复
热议问题