1

Windows 窗体 VB 应用程序。我在我的应用程序中添加了一个 splashScreen。它只闪烁了一秒钟然后就消失了,所以我在我的表单加载事件中添加了一个睡眠计时器......现在的问题是即使在应用程序退出后,splashScreen 仍然保持打开状态,而不是简单地在睡眠计时器结束时关闭......导致此问题的表单加载事件部分如下:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load

Threading.Thread.Sleep(5000)
Me.WindowState = FormWindowState.Maximized
Dim _year As String = System.DateTime.Now.Year.ToString

我正在使用通过转到 myproject 创建的股票 Splashscreen。它的代码如下: 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


    'Set up the dialog text at runtime according to the application's assembly information.  

    'TODO: Customize the application's assembly information in the "Application" pane of the project 
    '  properties dialog (under the "Project" menu).

    'Application title
    If My.Application.Info.Title <> "" Then

    Else
        'If the application title is missing, use the application name, without the extension
        'ApplicationTitle.Text = System.IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName)
    End If

    'Format the version information using the text set into the Version control at design time as the
    '  formatting string.  This allows for effective localization if desired.
    '  Build and revision information could be included by using the following code and changing the 
    '  Version control's designtime text to "Version {0}.{1:00}.{2}.{3}" or something similar.  See
    '  String.Format() in Help for more information.
    '
    '    Version.Text = System.String.Format(Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor, My.Application.Info.Version.Build, My.Application.Info.Version.Revision)

    Version.Text = System.String.Format(Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor)

    'Copyright info
    Copyright.Text = My.Application.Info.Copyright


End Sub

结束类

函数中没有更多与此相关的内容。其余部分用于填充表单标签和文本框...如果我删除 Threading.Thread.Sleep(5000) 行,则启动屏幕只会闪烁一秒钟,但完成后退出..有什么想法吗?

4

4 回答 4

4

答案不是使用Thread.Sleep而是设置MinimumSplashScreenDisplayTime显示初始屏幕的最小时间长度,以毫秒为单位。

要设置这个:

  1. 选择Project>[Your project name] Properties
  2. Application标签
  3. 单击View Application Events启动画面下拉菜单旁边的按钮
  4. MyApplication从对象选择下拉菜单中选择对象(左上角菜单)
  5. OnCreateSplashScreen从方法下拉菜单中选择方法声明(右上角菜单)
  6. OnCreateSplashScreen在方法中添加以下行MinimumSplashScreenDisplayTime = 10000

(如果您还没有这样做,您需要将启动屏幕表单设置为应用程序的启动屏幕,请参阅如何指定启动屏幕

于 2012-04-30T09:16:18.603 回答
1
FormName.MinimumSplashScreenDisplayTime = 10000 

它将显示启动画面 10 秒。

于 2012-04-30T11:49:31.683 回答
1

非常感谢那个人的帮助......它现在正在工作..但我不得不发表评论

  Me.WindowState = FormWindowState.Maximized

由于某种原因,它打破了最小飞溅时间..

于 2012-04-30T16:32:17.683 回答
0

这发生在我身上,它是由表单 OnLoad 事件中的错误引起的。我清除了错误,启动画面开始正常运行。

顺便说一句,我将此表单设置为最大化,该设置对启动画面没有影响

于 2015-06-10T14:50:53.800 回答