C# 如何在 .NET 中显示错误和警告消息框/如何自定义消息框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2109441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show Error & Warning Message Box in .NET/ How to Customize MessageBox
提问by claws
Using C# .NET (Winforms).
使用 C# .NET (Winforms)。
I want to know how can I show the message boxes with a Ding!!
sound & a red colored cross mark in it. This is what I'm talking about:
我想知道如何显示带有Ding!!
声音和红色十字标记的消息框。这就是我要说的:
How to do such things for my software, with custom errors and custom warnings?
如何使用自定义错误和自定义警告为我的软件执行此类操作?
MessageBox.Show("asdf");
doesn't give me customize.
不给我定制。
采纳答案by Andrew Hare
Try this:
尝试这个:
MessageBox.Show("Some text", "Some title",
MessageBoxButtons.OK, MessageBoxIcon.Error);
回答by Ahosan Karim Asik
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
);
回答by Onur Ad?yaman
MessageBox.Show(
"your message",
"window title",
MessageBoxButtons.OK,
MessageBoxIcon.Asterisk //For Info Asterisk
MessageBoxIcon.Exclamation //For triangle Warning
)
回答by Tides
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);