关闭启动表单会杀死应用程序 [英] Closing startup form kills application

查看:30
本文介绍了关闭启动表单会杀死应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个淡入然后淡出的表格,然后加载另一个表格.当新表单加载完毕后,它会关闭启动表单.

I make a form that fades in then fades out and loads another form up. when the new form has loaded it closes the the start up form.

问题是当它关闭这个启动表单时它会杀死我的应用程序.

Problem is when it closes this start up form it kills my apllication.

Public Class Splash
Dim appearance As Boolean = False

Private Sub Splash_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Opacity = 0
    FadeIn.Start()
End Sub

Private Sub FadeIn_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FadeIn.Tick
    If Not appearance Then
        Opacity += 0.015
    End If
    If Opacity = 1 Then
        appearance = True
    End If
    If appearance = True Then
        Opacity -= 0.015
        If Opacity = 0 Then
            Form1.Show()
        End If
    End If
End Sub
End Class

Public Class Form1

Private Function WebLoad()
    While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
        Application.DoEvents()
    End While
    Return 0
End Function
Private Function Login(ByVal User As String, ByVal Pass As String)
    WebBrowser1.Navigate("http://caan/SC5/SC_Login/aspx/login_launch.aspx?SOURCE=ESOLBRANCHLIVE")
    WebLoad()
    WebBrowser1.Document.GetElementById("txtUserName").SetAttribute("value", User)
    WebBrowser1.Document.GetElementById("txtPassword").SetAttribute("value", Pass)

    Dim allImgTags As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")
    If allImgTags IsNot Nothing Then
        For Each img As HtmlElement In allImgTags
            If img.GetAttribute("src").Contains("/images/SC5Login07.jpg") Then
                img.InvokeMember("Click")
                Exit For
            End If
        Next img
    End If
    Return 0
End Function

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

    Login(user, pass)
    WebBrowser2.Navigate("http://caan/SC5/SC_PartsCentre/aspx/partscentre_frameset.aspx")
    WebBrowser1.Navigate("http://caan/SC5/SC_RepairJob/aspx/RepairJob_frameset.aspx")
    Splash.Close()
End Sub
End Class

我知道有一个适当的启动画面形式,但它没有保持打开足够长的时间.在淡出时,它会关闭并启动我的应用

I am aware that there is a propper splash screen form but it doesnt stay open long enough. On its fadeout it just closes and launches my app

我的主要问题是如何阻止 splash.close() 关闭整个应用程序?

回答

现在排序,不会让我在底部回答...

Sorted this now, Wont let me answer at the bottem...

用于visualbasic express中提供的闪屏,并将我在msdn上找到的几行添加到应用程序事件

Used to splashscreen provided in visualbasic express and added a couple lines i found on msdn to the Application Events

应用事件

Namespace My

' The following events are available for MyApplication:
' 
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled exception.
' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
Partial Friend Class MyApplication
    Protected Overrides Function OnInitialize( _
ByVal commandLineArgs As  _
System.Collections.ObjectModel.ReadOnlyCollection(Of String)) As Boolean 
        Me.MinimumSplashScreenDisplayTime = 7000
        Return MyBase.OnInitialize(commandLineArgs)
    End Function

End Class
End Namespace

SplashScreen1.VB

Public NotInheritable Class SplashScreen1
Dim appearance As Boolean = False

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

    If My.Application.Info.Title <> "" Then
        ApplicationTitle.Text = My.Application.Info.Title
    Else
        ApplicationTitle.Text = System.IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName)
    End If

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

    Copyright.Text = My.Application.Info.Copyright

    Opacity = 0
    Fade.Start()
End Sub

Private Sub MainLayoutPanel_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MainLayoutPanel.Paint
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Fade.Tick
    Fade.Interval = 100
    If Not appearance Then
        Opacity += 0.1
    End If

    If appearance = True Then        
        Opacity -= 0.1
        End If
    If Opacity = 1 Then
        Fade.Interval = 5000
        appearance = True
    End If
End Sub
End Class

推荐答案

您应该在项目的应用程序页面中检查 Shutdown mode option http://msdn.microsoft.com/en-us/library/tzdks800(v=vs.90).aspx 并告诉我们Shutdown modeStartup form 的值.

You should check the Shutdown mode option in the application page of your project http://msdn.microsoft.com/en-us/library/tzdks800(v=vs.90).aspx and tell us the value of Shutdown mode and Startup form.

我猜关闭模式设置为When startup form closesStartup form设置为Splash.

在这种情况下,尝试将 Shutdown mode 设置为 On last window close 应该可以解决您的问题.

In this case, try to set Shutdown mode to On last window close and it should solve your issue.

这篇关于关闭启动表单会杀死应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆