VB.net 中的 MessageBox 持久化

发布于 2024-11-10 17:06:40 字数 182 浏览 6 评论 0原文

我使用 MessageBox 向用户提供一些信息,但是当弹出这样的框时,我希望它阻止对主窗口的访问。因此,在用户单击“确定”之前,他们不应该能够单击(甚至无法聚焦)其下方的窗口。

有人知道该怎么做吗?我注意到 MessageBox 的功能很少,所以也许我什至必须为此使用不同的对象。

I'm using MessageBox to give some information to the user, but when such a box pops up, I want it to block access to the main window. So, until the user has clicked "OK", they should not be able to click (or even focus on) the window that's below it.

Does anybody know how to do this? I've noticed that MessageBox has very few functions, so maybe I'll even have to use a different object for this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以往的大感动 2024-11-17 17:06:40

一个快速但肮脏的解决方案可能是对话框表单(项目->添加 Windows 窗体->对话框)。这为您提供了 MessageBox 的视觉可扩展性。

您可以调用 MessageBox 的 ShowDialog 方法,它当然会阻止对父窗口的访问。

当然还有其他方法。

例子:

' This is your Dialog you created by going Project->Add Windows Form->Dialog
Public Class MessageBoxDialog

  Public Overloads Sub ShowDialog(ByVal message As String)

    Me.txtMessage.Text = message

    ShowDialog()

  End Sub
End Class

' This is the form you want to call the message box on
Private Sub btnShowMsgBox_Click(sender As System.Object, e As System.EventArgs) _
                                Handles btnShowMsgBox.Click
    Dim messageBox As New MessageBoxDialog
    messageBox.ShowDialog("This is another way to show a MsgBox but allows greater extensibility.")
End Sub

A quick and dirty solution could be a dialog form (Project->Add Windows Form->Dialog). This gives you visual extensibility of your MessageBox.

You can call your MessageBox's ShowDialog method and it will of course block access to the parent window.

There are of course other methods.

Example:

' This is your Dialog you created by going Project->Add Windows Form->Dialog
Public Class MessageBoxDialog

  Public Overloads Sub ShowDialog(ByVal message As String)

    Me.txtMessage.Text = message

    ShowDialog()

  End Sub
End Class

' This is the form you want to call the message box on
Private Sub btnShowMsgBox_Click(sender As System.Object, e As System.EventArgs) _
                                Handles btnShowMsgBox.Click
    Dim messageBox As New MessageBoxDialog
    messageBox.ShowDialog("This is another way to show a MsgBox but allows greater extensibility.")
End Sub
星光不落少年眉 2024-11-17 17:06:40

就在我发帖后,我的朋友就给出了答案。通过调用 MessageBox.Show(mf, "text") (其中 mf 是主窗体),只要未单击“确定”按钮,mf 就会被禁用。我想发布这个问题毕竟有点愚蠢,但我希望它可以帮助其他遇到同样问题的人。

Just after I posted here, my friend came up with the answer. By calling MessageBox.Show(mf, "text") where mf is the main form, mf will be disabled as long as the OK button has not been clicked. I suppose this question was a bit silly to post after all, but I hope it might help others if they're stuck with the same problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文