3

我希望我的 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
4

3 回答 3

4

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

于 2013-01-07T17:29:08.543 回答
0

您的 timer1_tick 事件导致了此问题。Timer1 在启动画面加载时启用,根据 timer_interval,它可能永远不会在 form1 加载之前显示。你想让用户在这段时间内看到一些东西吗?

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

于 2013-01-07T17:41:07.387 回答
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
于 2014-05-06T13:24:17.073 回答