Set the MessageBox default button in C#


The fifth parameter to MessageBox.Show indicates the default button. The following code shows how the program displays a MessageBox with the second button as the default so it is initially selected when the message box appears.

// Display a message box with the second button the default.
private void btnButton2_Click(object sender, EventArgs e)
    DialogResult result = MessageBox.Show(
        "The second button is the default.",
    MessageBox.Show("You selected " + result.ToString());

That’s all there is to it. It’s not very complicated, it’s just not well known.

Download Example   Follow me on Twitter   RSS feed   Donate

This entry was posted in dialogs, MessageBox and tagged , , , , , , , , , . Bookmark the permalink.

2 Responses to Set the MessageBox default button in C#

  1. Subham says:

    How to change the text of “Yes” , “No” or “Cancel” ?

Comments are closed.