Var
ButtonNames: array[TMsgDlgBtn] of string = ('Yes', 'No', 'OK', 'Cancel', 'Abort', 'Retry', 'Ignore', 'All', 'NoToAll', 'YesToAll', 'Help');
function MessageDlgWithFocus(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; FocusBtn: TMsgDlgBtn;
HelpCtx: Longint): Integer;
var Btn: TComponent;
begin
with CreateMessageDialog(Msg, DlgType, Buttons) do
begin
try
HelpContext := HelpCtx;
Position := poScreenCenter;
Btn := FindComponent( ButtonNames[FocusBtn] );
if (Btn <> nil) and (Btn is TWinControl) then
ActiveControl := Btn as TWinControl;
Result := ShowModal;
finally
Free;
end;
end;
end;
If MessageDlgWithFocus('The confirmation message dialog with cancel button focus on default', mtConfirmation, [mbOk, mbCancel], mbCancel, 0) = mrOk Then
Do your stuffs ....
No comments:
Post a Comment