I have a form that is called w/ ShowDialog. Inside that form, I want to pop a message box to ask the user a question, but it doesn't show.

Form:

Dim someFrame as myFrame = new myFrame
someFrame.ShowDialog()

Then, inside that form:

Dim ans As MsgBoxResult
ans = MsgBox(transarr(16), MsgBoxStyle.YesNo + MsgBoxStyle.SystemModal, "WARNING!")

If ans = MsgBoxResult.Yes Then
  'do something
Else
 'do something else
End If

Is this possible to get working?

Dani AI

Generated

Yes — a dialog shown with ShowDialog can display a prompt. As noted, it is possible. For , the message box usually "not showing" comes from timing, ownership, threading, or a runtime error before the prompt runs. The usual fixes are simple and reliable.

Typical checklist to try:

  • Run the prompt on the UI thread. If code runs on a background thread the dialog may never appear or may be hidden.
  • Show the prompt after the form is visible (use the Shown event or defer with BeginInvoke) instead of in the constructor or too early in Load.
  • Give the message box the dialog as owner so window ordering and focus behave predictably.
  • Wrap the prompt in try/catch or verify variables (for example, ensure the array index used for the message text is valid) so an exception is not aborting the call.

Example pattern to run inside the dialog form (use Shown so the form is up, and set the owner explicitly):

Private Sub ThisForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
    Try
        Dim result = MessageBox.Show(Me, "Confirm action?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
        If result = DialogResult.Yes Then
            ' take action
        End If
    Catch ex As Exception
        ' log or handle unexpected errors that would prevent the prompt
    End Try
End Sub

If the prompt must run from Load or a constructor use BeginInvoke to defer it until after the form is created. For threading issues check Control.InvokeRequired/Invoke. Microsoft docs for MessageBox and form lifecycle are useful reference reading: MessageBox.Show and Form.Shown.

Recommended Answers

All 2 Replies

>Is this possible to get working?
Yes.

>Is this possible to get working?
Yes.

And that would be how? (Not exactly the most helpful post)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.