Dev/Delphi

Custom MessageDialog

파르페민트 2018. 7. 17. 10:18


 

기본 1)

buttonSelected := messagedlg('Confirmation',mtError, mbOKCancel, 0);                                


기본 2)

   buttonSelected := messagedlg('Custom dialog',mtCustom,

[mbYes,mbAll,mbCancel], 0);                                           


Delphi에서 기본으로 제공해주는 MessageDlg 함수를 사용

보통 이렇게 많이 사용하지만 버튼 Caption을 변경하여 사용자들에게 보여주고 싶을 때 아래와 같이 사용하면 된다.




function TfrmHmConsAppl.CustomMessageDlg(const Msg: string;
DlgType: TmsgDlgType; button: TMsgDlgButtons; Caption : array of string;
dlgcaption: string): integer;
var
aMsgDlg : TForm;
i : Integer;
Dlgbutton: Tbutton;
Captionindex : integer;
begin
aMsgDlg := createMessageDialog(Msg,DlgType, 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'):


출처 :
https://stackoverflow.com/questions/5417843/generic-dialog-with-custom-captions-for-buttons