创建无模式消息框
如何创建一个无模式消息框?我是否必须创建自己的 Windows 窗体类并使用它?如果是这样,是否有一种简单的方法来添加警告图标(而不是插入我自己的图像)并根据文本量调整大小?
How might one go about creating a Modeless MessageBox? Do I have to just create my own Windows Form class and use that? If so, is there an easy way of adding a warning icon (rather than inserting my own image of one) and resizing based on text volume?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
//没有commnet
需要更多线程和更多代码(我没有足够的时间来编写)来并发消息框。
//no commnet
needs more threads and more code(I don't have enough time to write) for concurrent messageboxes.
无需编写代码,您可以创建一个小表单,在构造函数中执行以下操作
SystemIcons.Application
SystemIcons.Asterix
SystemIcons.Error
SystemIcons.Exclamation
SystemIcons.Hand
SystemIcons.Information
SystemIcons.Question
SystemIcons.Shield
SystemIcons.Warning
SystemIcons.WinLogo
如果您确实需要,您可以监听按下“确定”按钮时触发的事件。
Short of writing the code, you could create a small form that in the constructor does the following
SystemIcons.Application
SystemIcons.Asterix
SystemIcons.Error
SystemIcons.Exclamation
SystemIcons.Hand
SystemIcons.Information
SystemIcons.Question
SystemIcons.Shield
SystemIcons.Warning
SystemIcons.WinLogo
If you really wanted, you could listen to an event that is fired when the OK button is pushed.
您可以使用标准系统警告图标
SystemIcons< /代码>
You can use the standard system warning icon using
SystemIcons
您必须使用表单并调用 showDialog()
对于图标,请使用
MessageBoxIcon.Warning
You have to either use form and call showDialog()
And for icons use
MessageBoxIcon.Warning
注意:这将创建一个模态对话框,这不是问题所问的
这里是示例代码
Note: this will create a Modal dialog box, which is not what the question is asking
here is a sample code
如果您需要一个在代码继续在后台运行时自动显示的消息框(该框仍然是模态的,并且将阻止用户使用其他窗口,直到单击“确定”),您始终可以在其自己的线程中启动该消息框并继续做你在原始线程中所做的事情:
If you need a message box that just displays itself while your code continues running in the background (the box is still modal and will prevent the user from using other windows until OK is clicked), you can always start the message box in its own thread and continue doing what ever you do in the original thread:
您必须创建一个表单并使用
Show()
以无模式方式显示它。MessageBox.Show(...)
表现出 Modal,如 ghiboz 的示例所示; “消息描述”将一直显示,直到用户按下按钮。使用
MessageBox.Show(...)
,一旦消息框关闭,您就可以得到结果;对于无模式消息框,您的代码必须具有一种机制,例如当用户最终在消息框中选择某些内容时做出反应的事件。You'll have to create a Form and use
Show()
to display it Modeless.MessageBox.Show(...)
behaved Modal as seen in the example by ghiboz; "Description of the message" is displayed until the user presses a button.With
MessageBox.Show(...)
you get the result as soon as the messagebox is closed; with a modeless message box, your code will have to have a mechanism such as an event to react when the user eventually selects something on your message box.