加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB.NET一个秘密的类:简单但强大

发布时间:2020-12-16 22:47:42 所属栏目:大数据 来源:网络整理
导读:Namespace My '右击解决方案的属性时,在“Application(应用)”中,单击“View Application Events”便自动产生一个新的ApplicationEvents.vb。在此 '里面共有五个事件。 '这是特别的类,几乎被很多开发者忽略,但是功能最简单,却是却实用的类, ' The foll
Namespace My
    '右击解决方案的属性时,在“Application(应用)”中,单击“View  Application Events”便自动产生一个新的ApplicationEvents.vb。在此
    '里面共有五个事件。

    '这是特别的类,几乎被很多开发者忽略,但是功能最简单,却是却实用的类,
    ' 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
        '检测计算是否接入网络
        Private Sub MyApplication_NetworkAvailabilityChanged(sender As Object,e As Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs) Handles Me.NetworkAvailabilityChanged
            SetConnectionStatus(e.IsNetworkAvailable)
        End Sub

        '当应用程序各个窗体都关闭了。这个程序才运行,也是最后运行的程序
        Private Sub MyApplication_Shutdown(sender As Object,e As System.EventArgs) Handles Me.Shutdown
            MsgBox("程序已经关闭运行!")
        End Sub

        '当应用程序最开始启动时就运行了。早于任何窗体,在这个地方来初始化变量是最好的
        Private Sub MyApp_Startup(ByVal sender As Object,ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
            ' When the application starts,set the connection status on the status strip
            MsgBox("程序将要开始启动")

        End Sub

        Public Sub SetConnectionStatus(ByVal connected As Boolean)
            'With My.Forms.MainForm.ConnectedStatusLabel
            '    If (connected) Then
            '        .Image = My.Resources.connected.ToBitmap
            '        .Text = My.Resources.ConnectedText
            '    Else
            '        .Image = My.Resources.disconnected.ToBitmap
            '        .Text = My.Resources.DisconnectedText
            '    End If
            'End With
        End Sub

        Private Sub MyApplication_StartupNextInstance(sender As Object,e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance
            MsgBox("程序已经启动一次了")
        End Sub

        '当程序在运行中出错,而未作处理时,它是来收集错误并提示错误内容
        Private Sub MyApplication_UnhandledException(sender As Object,e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
            MsgBox("程序在运行中出现错误")
        End Sub
    End Class


End Namespace

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读