Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual basic 2010 Check if file exists on form load

I would like my Visual Basic app to run a splash screen with a progress bar and after that to check if file exists, but I have a problem since as soon as I start and the splash screen shows up the file checker fires up, but I would like it to check when form1 loads and not splash screen. Here is my code, I could use an advice:

Splash screen :

Public NotInheritable Class SplashScreen1

    'TODO: This form can easily be set as the splash screen for the application by going to the "Application" tab
    '  of the Project Designer ("Properties" under the "Project" menu).       

    Private Sub Splashscreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim Dte As DateTime = DateTime.Now
        Label2.Text = FormatDateTime(Dte, DateFormat.LongDate)

        Timer1.Start()
        Timer2.Start()

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Form1.Show()
            Me.Close()
        End If

    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        ProgressBar1.PerformStep()
    End Sub
End Class

Form 1 :

Imports System.Net
Imports System.IO
Public Class Form1
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If My.Computer.FileSystem.FileExists(Application.StartupPath & "/read me.txt") Then
            MsgBox("file found")
        Else
            MsgBox("not found")
        End If

    End Sub
End Class
like image 461
user1955680 Avatar asked Dec 20 '25 23:12

user1955680


1 Answers

Try moving your Form1 code from the Load event to the Shown event. Load is run before the form is visible to the user, which is not what you want from what I understand.

like image 119
Jason Tyler Avatar answered Dec 23 '25 13:12

Jason Tyler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!