Задать кнопку по умолчанию для диалога
Оформил: DeeCo
Автор: http://www.swissdelphicenter.ch
function DefMessageDlg(const ACaption: string;
const Msg: string;
DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons;
DefButton: Integer;
HelpCtx: Longint): Integer;
var
i: Integer;
btn: TButton;
begin
with CreateMessageDialog(Msg, DlgType, Buttons) do
try
Caption := ACaption;
HelpContext := HelpCtx;
for i := 0 to ComponentCount - 1 do
begin
if (Components[i] is TButton) then
begin
btn := TButton(Components[i]);
btn.default := btn.ModalResult = DefButton;
if btn.default then ActiveControl := btn;
end;
end;
Result := ShowModal;
finally
Free;
end;
end;
// Sets the focus on the "No"-Button
// Setzt den Fokus auf den "Nein"-Button
procedure TForm1.Button1Click(Sender: TObject);
begin
if DefMessageDlg('Title',
'....?',
mtConfirmation,
mbYesNoCancel,
mrNo,
0) = mrYes then
ShowMessage('....');
end;
|