【发布时间】:2019-12-15 06:10:15
【问题描述】:
我正在尝试在 C# 代码和我找到的示例中添加一个确认消息框,并添加了以下示例,但我不断收到错误消息“当前上下文中不存在名称‘MessageBox’”我很漂亮C# 新手,需要帮助,因为我需要页面用户的确认消息。
我已尝试添加 Using system.windows.form 以查看是否可以解决消息框问题,但到目前为止还没有成功
const string message = "Are you sure that you would like to close the form?";
const string caption = "Form Closing";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
// If the no button was pressed ...
if (result == DialogResult.No)
{
// cancel the closure of the form.
e.Cancel = true;
}
基于我将执行的比较,我需要此消息框来提示并询问用户是否确定要继续,如果不是,则返回页面,如果是,则执行新代码.
【问题讨论】:
-
同时告诉我们您使用的是什么 API; ASP.NET、WinForm、WPF、UWP。请注意到目前为止您得到的答案都假设 WinForms。
-
老实说,如果我使用的是 asp.net、winform、WPF 或 UWP,我不知道去哪里找,你能告诉我去哪里找吗?我很沮丧,我看到的每个示例都表明我需要按我的方式设置代码,但我无法让它工作。
标签: c# messagebox