2013-06-10 24 views
10
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(); 
      } 

Hiện tại khi hộp thông báo xuất hiện nút 'Có' được tô sáng. Thay vào đó, tôi muốn nút 'Không' được đánh dấu. Vì vậy, mặc định 'Không'.Mặc định Không có trong msgbox C#

Làm cách nào để thực hiện việc này?

+0

Tôi đoán nó có một tình trạng quá tải mà phải mất MessageBox Nút mặc định – V4Vendetta

+4

Có 'MessageBoxDefaultButton' trong mã của bạn nên có đủ của một gợi ý. -1 vì không nỗ lực. – Stijn

+0

@ V4Vendetta anh ta đã sử dụng tình trạng quá tải đó, chỉ cần thay đổi giá trị enum. – psubsee2003

Trả lời

17

Thay đổi này

MessageBoxDefaultButton.Button1); 

để

MessageBoxDefaultButton.Button2); 
12

thay đổi này được thông báo hộp:

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

Thay đổi MessageBoxDefaultButton tham số của phương pháp này để MessageBoxDefaultButton.Button2

0

defaultResult MessageBoxResult

Giá trị MessageBoxResult chỉ định kết quả mặc định của hộp thư.

[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);

Các vấn đề liên quan