Board index » delphi » Messagebox: preselect Answer

Messagebox: preselect Answer

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 Gundermann

 

Re:Messagebox: preselect Answer


If Application.MessageBox('Show No as being the Default Button, and
check for no as a result.', 'Example',
MB_YESNO+MB_DEFBUTTON2+MB_APPLMODAL) = ID_NO Then....

You can change MD_DEFBUTTON[Number] to button required.

Andy Vines...

Quote
Bjoern Gundermann <gunderm...@gundermann-software.de> wrote in message

news:7ts2q4$e5v1@forums.borland.com...
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 Gundermann

Re:Messagebox: preselect Answer


perhaps by swapping them ?
isn't the first one preselected ?

Rene

Quote
Bjoern Gundermann wrote:

> 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 Gundermann

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!

Re:Messagebox: preselect Answer


Quote
>Bjoern Gundermann wrote:

>If I generate a messagebox with an yes and no answer button, the yes >button is preselected. How can I preselect the no button?

Set the flag MB_DEFBUTTONn (replace n with the number of the button you
want as default).
________
Andreas

Re:Messagebox: preselect Answer


Quote
>perhaps by swapping them ?

There are two questions :-)

- How?
- Why?

Other Threads