Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

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
Posted
Comments
Sergey Alexandrovich Kryukov 10-Jan-12 3:14am    
What is your UI library? Type of application? Tag it.
--SA
Sanjay_Prajapati 10-Jan-12 3:37am    
It is a window application.

MsgBox function will always open new window you will need an other way to display error message if no user input is required
 
Share this answer
 
Comments
Sanjay_Prajapati 10-Jan-12 6:13am    
Hi,
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.
Hi
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
        Try
            '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))
            t.Start(ex)
        End Try
        
    End Sub

    Private Sub shoMsg(ex As Exception)
        MessageBox.Show(ex.Message)
    End Sub
End Class
 
Share this answer
 
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.
 
Share this answer
 
Comments
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??
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900