gpt4 book ai didi

c# - 捕获 MessageBox 结果

转载 作者:太空宇宙 更新时间:2023-11-03 18:40:05 25 4
gpt4 key购买 nike

我正在尝试让用户确认他们是否要使用 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 在我打开文件对话框的代码中的其他地方。显然,这不是检查它的正确方法。

最佳答案

你必须请求 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");
}

关于c# - 捕获 MessageBox 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9897920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com