我試圖讓用戶確認他們是否想要使用MessageBox刪除產品並捕獲其結果。這是我的代碼:捕獲MessageBox結果
// Confirm if the user really wants to delete the product
DialogResult result = MessageBox.Show("Do you really want to delete the product \"" + productName + "\"?", "Confirm product deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.OK)
{
MessageBox.Show("deleted");
}
當我運行的代碼,並嘗試刪除產品,被刪除從不顯露。在MSDN頁面上它使用MessageBoxResult
而不是DialogResult
,但Visual Studio不能識別MessageBoxResult
,而我在我的代碼的其他地方使用DialogResult
打開文件對話框。顯然,這不是檢查它的正確方法。