Delphi 更改消息对话框中的按钮标题


本文整理自网络,侵删。

 
unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm2 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

function MyMessageDialog(const Msg: string; DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons; Captions: array of string): Integer;
var
  aMsgDlg: TForm;
  i: Integer;
  dlgButton: TButton;
  CaptionIndex: Integer;
begin
  { Create the Dialog }
  aMsgDlg := CreateMessageDialog(Msg, DlgType, Buttons);
  captionIndex := 0;
  { Loop through Objects in Dialog }
  for i := 0 to aMsgDlg.ComponentCount - 1 do
  begin
   { If the object is of type TButton, then }
    if (aMsgDlg.Components[i] is TButton) then
    begin
      dlgButton := TButton(aMsgDlg.Components[i]);
      if CaptionIndex > High(Captions) then Break;
      { Give a new caption from our Captions array}
      dlgButton.Caption := Captions[CaptionIndex];
      Inc(CaptionIndex);
    end;
  end;
  Result := aMsgDlg.ShowModal;
end;


procedure TForm2.Button1Click(Sender: TObject);

begin
  if MyMessageDialog('How much...?', mtConfirmation, mbOKCancel,
    ['1', '2']) = mrOk then
    ShowMessage('"1" clicked')
  else
    ShowMessage('"2" clicked');
end;



end.

相关阅读 >>

Delphi datetimepicker控件日期格式

Delphi 让子窗体显示在任务栏上

Delphi 限制form窗体为固定的大小

Delphi生成32位随机数

Delphi 用 tbytesstream 类实现的读文件为十六进制字符的函数

Delphi指针

Delphi模仿“千千静听”滚动标题栏,非常简单!

Delphi url取得文件名

Delphi 使用shellexecuteex运行应用程序并等待完成

Delphi 纯window系统api实现的ssl客户端

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...