Search code examples
vb.netmessageboxmsgbox

First MessageBox not showing on FormLoad Event


In my application I want one of my Windows Form to show a MessageBox if something is true but I am not able to get it but I can solve that by throwing some other event before that MessageBox, I mean it works if some other action is done before that

My Code for NotWorking MessageBox:

Private Sub MainInterface_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        If My.Settings.RowName <> "" Then
            If My.Settings.LastModifiedCheck <> SOMETHING Then
                MsgBox("Hello :)")
            End If
        End If
End Sub

My Code for Working MessageBox:

Private Sub MainInterface_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    If My.Settings.RowName <> "" Then
        If My.Settings.LastModifiedCheck <> SOMETHING Then
            MsgBox("Hello :)")
            MsgBox("Hello2 :)")
        End If
    End If
End Sub

In this code what it will do is, it will show the second MsgBox, i.e, "Hello 2 :)" but will still ignore the first MsgBox which was just "Hello :)"

Edit:

If I add the style MsgBoxStyle.Critical to the MessageBox Style I can hear the Critical Sound but still don't get the MessageBox. No idea what's going on. It seems very bad BTW, I mean this looks impossible! how can a MsgBox closes itself automatically.


Solution

  • Okay, So I solved my problem with this partial solution but still wonder what was the problem...

    Instead of adding the MsgBox event inside the Form.Load Event I inserted the even inside Form.Shown event

    Example

    Private Sub MainInterface_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        If My.Settings.RowName <> "" Then
            If My.Settings.LastModifiedCheck <> SOMETHING Then
                MsgBox("Hello :)")
            End If
        End If
    End Sub
    

    And it worked fine!