Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default No in msgbox C#

Tags:

c#

.net

winforms

MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result = MessageBox.Show("Are there any other products in the carton?", "Question", buttons, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

            if (result == DialogResult.Yes)
            {
                trans.Rollback();
                MessageBox.Show("Please go to the controll room for new packaging", "Message");
                frmHome main = new frmHome(empid);
                main.Show();
                this.Hide();
            }

            if (result == DialogResult.No)
            {
                trans.Commit();
                frmPalletCartonAllocation pca = new frmPalletCartonAllocation(pack, companyIdNo, skuIdNo, UnitsInCarton, UnitsInPack, carton_Code, orderNo, grvIdNo, empid);
                pca.Show();
                this.Hide();
            }

At the moment when the message box appear the 'Yes' button gets highlighted. I want the 'No' button to get highlighted instead. So default 'No'.

How do I do this?

like image 230
Werner van den Heever Avatar asked Jun 10 '13 11:06

Werner van den Heever


People also ask

Which is the default MessageBox button?

The first button on the message box is the default button.

What is the 3rd parameter in MessageBox show ()?

The first parameter msg is the string displayed in the dialog box as the message. The second and third parameters are optional and respectively designate the type of buttons and the title displayed in the dialog box. MsgBox Function returns a value indicating which button the user has chosen.

What does MessageBox return?

Return valueIf a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing ESC will no effect - unless an MB_OK button is present.

What is the 2nd parameter in MessageBox show ()? *?

The second parameter is the title of the Message Box. An ok button is also present to close the dialog. Example: MessageBox. Show( “Message”, ”Title”).


1 Answers

Change this

MessageBoxDefaultButton.Button1);

to this

MessageBoxDefaultButton.Button2);
like image 131
Mike Perrenoud Avatar answered Sep 22 '22 17:09

Mike Perrenoud