Seyting a MessageBoxButtons.YesNo default to No

Hi,

How do I set the default button to No?  Please don't tell me I can't use a stock message box for that?

Bob
ba272Asked:
Who is Participating?
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
It's almost just a matter of ;

        string message = "You did not enter a server name. Cancel this operation?";
        string caption = "No Server Name Specified";
        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
        DialogResult result;

        // Displays the MessageBox.

        result = MessageBox.Show(this, message, caption, buttons,
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

Ref: http://msdn2.microsoft.com/en-us/library/system.windows.forms.messageboxdefaultbutton.aspx
0
 
Éric MoreauSenior .Net ConsultantCommented:
Hi ba272,

You need to use the MessageBoxDefaultButton arguments. Something like this:

        Dim Message As String = "You did not enter a server name. Cancel this operation?"
        Dim Caption As String = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, _
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)




Cheers!
0
 
ba272Author Commented:
No speak.  I C#, can you?
0
All Courses

From novice to tech pro — start learning today.