2012-04-30 60 views
1

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

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创建一个股票闪屏。它的代码如下: 公共NotInheritable类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 

末级

没有什么更多的与此相关的功能在所有..其余部分用来填充表单标签和textboxes ...如果我删除了Threading.Thread.Sleep(5000)这一行,初始屏幕只会闪烁一秒,但在完成后退出。任何想法?

+0

无影响u能告诉我其中U调用闪屏的代码。从哪里创建启动画面的对象并使其可见。 – kbvishnu

+0

查看输出窗口,您是否看到“第一次机会异常”通知? –

+0

输出中没有第一次机会异常通知.. – Skindeep2366

回答

4

答案是不使用Thread.Sleep但设置MinimumSplashScreenDisplayTime

要设置该(时间的最小长度,以毫秒为单位被显示在初始屏幕):

  1. 选择Project>[Your project name] Properties
  2. Application标签
  3. View Application Events按钮,点击旁边的SP睫毛屏幕下拉
  4. 选择从对象选择的MyApplication对象下拉(左上菜单)
  5. 选择从方法OnCreateSplashScreen方法的声明下拉(右上菜单)
  6. 添加follwing线在OnCreateSplashScreen方法MinimumSplashScreenDisplayTime = 10000

(如果您还没有这样做的话,你需要设置你的闪屏形式进行应用程序的启动画面,看到how to specify the splashscreen

+0

还有更多的,该属性已设置为2秒。 –

+0

@HansPassant - 是2秒是默认的,这就是为什么我认为OP没有为项目指定启动画面 –

+0

我实际上确实通过“myproject”指定了启动画面......如果我进入该splashscreen视图并右键单击,选择属性那里没有财产那里有任何类型的时间值.. – Skindeep2366

1
FormName.MinimumSplashScreenDisplayTime = 10000 

它会显示闪屏10秒。

1

感谢很多关于一个帮助......这是现在的工作。但我不得不注释掉

Me.WindowState = FormWindowState.Maximized 

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

+0

有时候,我的初始形式有一个例外,这导致(我不知道为什么)使启动画面保持打开状态。 –

+0

@AnonymousPi在try/catch块中抛出初始屏幕代码,并打破异常。 – Skindeep2366

+0

当然,你可以尝试去除异常,特别是如果你不需要它。 –

0

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

顺便说一句,我有这样的形式设置为最大化,即设置有开机画面

相关问题