[英]How to show Error & Warning Message Box in .NET/ How to Customize MessageBox
Using C# .NET (Winforms).使用 C# .NET (Winforms)。
I want to know how can I show the message boxes with a Ding!!
我想知道如何用
Ding!!
来显示消息框Ding!!
sound & a red colored cross mark in it.声音和一个红色的十字标记。 This is what I'm talking about:
这就是我要说的:
How to do such things for my software, with custom errors and custom warnings?如何使用自定义错误和自定义警告为我的软件执行此类操作?
MessageBox.Show("asdf");
doesn't give me customize.不给我定制。
Try this:尝试这个:
MessageBox.Show("Some text", "Some title",
MessageBoxButtons.OK, MessageBoxIcon.Error);
Try details: use any option..尝试细节:使用任何选项..
MessageBox.Show("your message",
"window title",
MessageBoxButtons.OK,
MessageBoxIcon.Warning // for Warning
//MessageBoxIcon.Error // for Error
//MessageBoxIcon.Information // for Information
//MessageBoxIcon.Question // for Question
);
MessageBox.Show(
"your message",
"window title",
MessageBoxButtons.OK,
MessageBoxIcon.Asterisk //For Info Asterisk
MessageBoxIcon.Exclamation //For triangle Warning
)
You should add namespace if you are not using it:如果你不使用它,你应该添加命名空间:
System.Windows.Forms.MessageBox.Show("Some text", "Some title",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Error);
Alternatively, you can add at the begining of your file:或者,您可以在文件的开头添加:
using System.Windows.Forms
and then use (as stated in previous answers):然后使用(如之前的答案所述):
MessageBox.Show("Some text", "Some title",
MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult result = MessageBox.Show("Are you sure you want to exit?",
"", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
Application.Exit();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.