您现在的位置:首页 >> VCL >> VCL >> 内容

Delphi中如果点击MessageDlg中的X会出现?

时间:2011/9/3 16:24:05 点击:

  核心提示:600) this.width = 600;'>unit Unit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Gra...

600) this.width = 600;">

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

function MessageDlgEx(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; FocusBtn, CloseBtn: TMsgDlgBtn; HelpCtx: Longint): Integer;
const
  ModalResults: array[TMsgDlgBtn] of Integer = (mrYes, mrNo, mrOk, mrCancel, mrAbort, mrRetry, mrIgnore, mrAll, mrNoToAll, mrYesToAll, 0) ;
begin
  with CreateMessageDialog(Msg, DlgType, Buttons, FocusBtn) do
  try
    HelpContext := HelpCtx;
    Position := poScreenCenter;
    Result := ShowModal;
    //if there's a cancel button, ignore CloseBtn.
    if (result = mrCancel) AND (NOT (mbCancel in Buttons)) then result := ModalResults[CloseBtn];
  finally
    Free;
  end;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  if mrNo = MessageDlg('Destroy all data?', mtWarning, [mbYes, mbNo], -1, mbNo) then
    Exit
  else
  begin
    ShowMessage('destroy all files');
  end;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
  if mrNo = MessageDlgEx('Destroy all data?'+ #13#10 + 'Don''t click the X button!',mtWarning,[mbYes, mbNo], mbNo, mbNo, -1) then
    Exit
  else
  begin
    ShowMessage('destroy all files - will not happen if [x] clicked');
  end;
end;

end.

作者:站长 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
本类推荐
  • 没有
本类固顶
  • 没有
  • 盒子文章(www.2ccc.com) © 2020 版权所有 All Rights Reserved.
  • 沪ICP备05001939号