Jam*_*son 1 c# messagebox dialogresult
我试图让用户确认是否要使用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");
}
Run Code Online (Sandbox Code Playgroud)
当我运行代码并尝试删除产品时,删除永远不会显示.在MSDN页面上,它表示使用MessageBoxResult而不是DialogResultVisual Studio无法识别MessageBoxResult,我DialogResult在我的代码中的其他地方用于打开文件对话框.显然,这不是检查它的正确方法.
你必须要求 DialogResult.Yes
// 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.Yes)
{
MessageBox.Show("deleted");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7491 次 |
| 最近记录: |