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?
The first button on the message box is the default button.
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.
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.
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”).
Change this
MessageBoxDefaultButton.Button1);
to this
MessageBoxDefaultButton.Button2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With