Ответ 1
Измените это
MessageBoxDefaultButton.Button1);
к этому
MessageBoxDefaultButton.Button2);
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();
}
В тот момент, когда появляется окно сообщения, кнопка "Да" подсвечивается. Я хочу, чтобы кнопка "Нет" была подсвечена. Поэтому по умолчанию "Нет".
Как это сделать?
Измените это
MessageBoxDefaultButton.Button1);
к этому
MessageBoxDefaultButton.Button2);
измените окно сообщения на:
DialogResult result = MessageBox.Show(
"Are there any other products in the carton?",
"Question",
buttons,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2
);
Измените параметр MessageBoxDefaultButton метода на MessageBoxDefaultButton.Button2
defaultResult MessageBoxResult
Значение MessageBoxResult, которое указывает результат по умолчанию в поле сообщения.
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult);
SampleCode:
MessageBox.Show("Message", "Caption", MessageBoxButton.YesNo, MessageBoxImage.Stop, MessageBoxResult.No);