Click here to Skip to main content
14,601,122 members
Rate this:
Please Sign up or sign in to vote.
See more:

I am getting problem in msgbox.
I display error in msgbox.When I disply error in msgbox , it opens new window for that and in results my form can be accessed at that time. I dont want to be accessed my form when it shows error.

Please help...

Thank You
What is your UI library? Type of application? Tag it.
Sanjay_Prajapati 10-Jan-12 3:37am
It is a window application.
Rate this:
Please Sign up or sign in to vote.

Solution 1

MsgBox function will always open new window you will need an other way to display error message if no user input is required
Sanjay_Prajapati 10-Jan-12 6:13am
I know that Msgbox function will always open new window.But in my window application ,there is a form which display Msgbox when error occurs but it works like showdialog so without pressing "OK" button in msgbox dialog you can't do anything.And in some form it open msgbox like we open a new form.
Rate this:
Please Sign up or sign in to vote.

Solution 2

to get the desired results 2 ways r there
1. you can create unmanaged message box
2. show the messagebox in another thread

here i've shown the 2nd one

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            'do some work
            'for instance I'm intentionally creating an exception
            Throw New Exception("test error message")
        Catch ex As Exception
            Dim t As New Threading.Thread(New Threading.ParameterizedThreadStart(AddressOf shoMsg))
        End Try
    End Sub

    Private Sub shoMsg(ex As Exception)
    End Sub
End Class
Rate this:
Please Sign up or sign in to vote.

Solution 4

If you are using a custom dialog to show the error, then use the ShowDialog() call instead of the Show() call to display it. That will make your form inaccessible while the error is being displayed. If you use the built in MessageBox object, then it automatically will be modal.
Sanjay_Prajapati 10-Jan-12 23:24pm
Hi Marcus,
I've already did what you say but I can't understand why it is not working??
Rate this:
Please Sign up or sign in to vote.

Solution 3

you can simply do it see

when you want to open a msgbox show your msgbox form by showdialog

on formload of msgbox put your error msg by passing it from the last form

on okbtn click close this form

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100