带有自定义按钮标题的通用对话框 [英] Generic dialog with custom captions for buttons
本文介绍了带有自定义按钮标题的通用对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这个问题从以前就一直存在(例如 显示自定义消息对话框的最佳方式),但我仍然找不到我想要的.
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.
我是这样开始的:
class function TAttracsForm.MessageDlg(const aMsg: string; aDlgType: TMsgDlgType; Buttons: TMsgDlgButtons; aCaptions: array of String; aDefault: TMsgDlgBtn): TModalResult;
var
vDlg: TForm;
i: Integer;
begin
if aButtons.Count = aCaptions.Count then
begin
vDlg := CreateMessageDialog(aMsg, aDlgType, Buttons);
try
for i := 0 aCaptions.Count - 1 do
TButton(vDlg.FindComponent(Buttons[i].Caption)).Caption := aCaptions[i];
vDlg.Position := poDefaultPosOnly;
Result := vDlg.ShowModal;
finally
vDlg.Free;
end;
end;
end;
调用看起来像:
if (MessageDlg('Really quit application ?', mtWarning,
[mbNo, mbCancel, mbYes], {'No save', 'Cancel', 'Save'}) = mrYes) then
但是上面的代码当然不能编译.我不知道如何在循环中获取一个集合中的一项,以及如何在一开始就获取它的总数.
But the above code of course don't compile. I don't know how to get one item of an set in the loop and how to get the total count of it in the beginning.
推荐答案
你可以使用这个代码:
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;
例如:
MyMessageDlg('Hello World!', mtInformation, [mbYes, mbNo],
['Yessss','Noooo'], 'New MessageDlg Box'):
这篇关于带有自定义按钮标题的通用对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文