Re:Messagebox: preselect Answer
Quote
> If I generate a messagebox with an yes and no answer button, the yes button
> is preselected. How can I preselect the no button?
Bj?rn,
use this one instead of MessageDlg, or use Windows.MessageBox. The latter
allows you to include the MB_DEFBUTTON2 constant into the uType parameter to
specify that the second button should be the default one.
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; { For }
Result := ShowModal;
finally
Free;
end;
End;
procedure TForm1.Button2Click(Sender: TObject);
begin
If DefMessageDlg( 'Please confirm',
'Do you want to format your harddisk now?',
mtConfirmation,
mbYesNoCancel,
mrno,
0 ) = mrYes
Then
ShowMessage('Formatting disk...');
end;
Peter Below (TeamB) 100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!