Samuel Nicholson
Samuel Nicholson

Reputation: 3629

VB.net working splash screen

So I've been trying to work out how to get my splash screen working. When my program starts I'm going to add a number of checks and I've got a progress bar that I'm updating next to a little logo.

My problem is any code I call in the splash_load runs before my form displays? I added the splashscreen from Windows Forms > Splash Screen and I set it to the "startup form" in my application settings.

For now I'm performing a simple MySQL Connection test, but my splash screen doesn't display until the whole sub has finished running?

splash.vb

Public NotInheritable Class splash

    Private Sub splash_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        mysql.connectionTest()
    End Sub

End Class

mysql.vb

Public Shared Sub connectionTest()
        Using SQLConnection As New MySqlConnection(My.Settings.mtConnStr)
            Try
                SQLConnection.Open()
                MessageBox.Show("Connection OK!")
            Catch ex As Exception
                MsgBox(ex.Message.ToString)
                Application.Exit()
            Finally
                SQLConnection.Close()
            End Try

        End Using
    End Sub

Upvotes: 0

Views: 1729

Answers (1)

APrough
APrough

Reputation: 2701

Your problem is that you are calling the connectionTest in the Load event. The form does not show until that event is completed. You could move that one line of code to the Splash_Shown event instead, and it should process after the form is loaded and visible.

Upvotes: 1

Related Questions