Search code examples
vb.netfocusmessagebox

Default focused button of yes/no MessageBox


How can I achieve this? Didn't find anything useful in the doc

I want to do this because of a pop-up "Are you really sure to want to remove [...]" and I want the "No" button to be preselected in case the user miss-click on his enter key.


Solution

  • The answer your are looking for is MessageBoxDefaultButton.Button2

    DialogResult result = MessageBox.Show(
        "Are you sure ....?",
        "Question",
        buttons,
        MessageBoxIcon.Question,
        MessageBoxDefaultButton.Button2
    );