如何在Delphi中显示带有两个按钮(继续/关闭)的对话框

Raf*_*ari 6 delphi delphi-2010

我想创建一个警告对话框,询问用户注册期间输入的信息是否正确,并询问他是否要继续或关闭该对话框并更正其信息.

Mik*_*son 11

var
  td: TTaskDialog;
  tb: TTaskDialogBaseButtonItem;
begin
  td := TTaskDialog.Create(nil);
  try
    td.Caption := 'Warning';
    td.Text := 'Continue or Close?';
    td.MainIcon := tdiWarning;
    td.CommonButtons := [];

    tb := td.Buttons.Add;
    tb.Caption := 'Continue';
    tb.ModalResult := 100;

    tb := td.Buttons.Add;
    tb.Caption := 'Close';
    tb.ModalResult := 101;

    td.Execute;

    if td.ModalResult = 100 then
      ShowMessage('Continue')
    else if td.ModalResult = 101 then
      ShowMessage('Close');

  finally
    td.Free;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

注意: 这仅适用于Windows Vista或更高版本.

  • 关闭通常意味着关闭对话框,并在没有选项时使用.继续和取消通常是配对的. (3认同)
  • +1完整答案,(虽然'close`是一个非常糟糕的按钮标题,因为它的一般含糊不清和无意义:-) (2认同)

Vib*_*nRC 8

var
  AMsgDialog: TForm;
  abutton: TButton;
  bbutton: TButton;
begin

  AMsgDialog := CreateMessageDialog('This is a test message.', mtWarning,[]);
  abutton := TButton.Create(AMsgDialog);
  bbutton :=  TButton.Create(AMsgDialog);

  with AMsgDialog do

    try

      Caption := 'Dialog Title' ;
      Height := 140;
      AMsgDialog.Width := 260 ;

      with abutton do
      begin
        Parent := AMsgDialog;
        Caption := 'Continue';
        Top := 67;
        Left := 60;
        // OnClick :tnotyfievent ;
      end;

      with bbutton do
      begin
        Parent := AMsgDialog;
        Caption := 'Close';
        Top := 67;
        Left := 140;
        //OnClick :tnotyfievent ;
      end;

       ShowModal ;

    finally
      abutton.Free;
      bbutton.Free;
      Free;
    end;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Pre*_*ias 7

如果delphi那么

if mrYes=MessageDlg('Continue?',mtwarning,[mbYes, mbNo],0) then 
  begin
        //do somthing
  end
else
exit; //go out
Run Code Online (Sandbox Code Playgroud)

  • 你只能为messageDlg mbYes,mbNo,mbOK,mbCancel,mbAbort,mbRetry,mbIgnore,mbAll,mbNoToAll,mbYesToAll,mbHelp (2认同)