Visual Basic 2010检查表单加载是否存在文件

时间:2013-01-07 17:14:16

标签: .net vb.net visual-studio-2010 if-statement

我希望我的Visual Basic应用程序运行带有进度条的启动画面,然后检查文件是否存在,但是我有一个问题,因为我一开始并且启动画面显示文件检查器启动,但我想检查何时加载form1而不是启动画面。这是我的代码,我可以使用建议:

启动画面

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

表单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

3 个答案:

答案 0 :(得分:4)

尝试将Form1代码从Load事件移动到Shown事件。在表单对用户可见之前运行加载,这不是我所理解的。

答案 1 :(得分:0)

您的timer1_tick事件导致此问题。在启动屏幕加载时启用Timer1,并且根据timer_interval,它可能在form1加载之前永远不会显示。您希望用户在此期间看到某些内容吗?

进度条表示正在执行一系列操作或一系列操作。你有什么需要进度条的?如果你想要发生事情的错觉,请确保你的timer1间隔大于你的timer2间隔,因为timer1控制在加载form1之前启动画面的可见时间。

答案 2 :(得分:0)

If ProgressBar1.Value = ProgressBar1.Maximum Then
      Form1.Show()
      Me.Close()
End If

更改为:

If ProgressBar1.Value = ProgressBar1.Maximum Then
      Form1.Visible = True
      Me.Visible = False
End If