.net中简单而实用的类
来源:互联网 发布:照片拼贴软件 java 编辑:程序博客网 时间:2024/05/16 06:33
01.Namespace My 02. '右击解决方案的属性时,在“Application(应用)”中,单击“View Application Events”便自动产生一个新的ApplicationEvents.vb。在此 03. '里面共有五个事件。 04. 05. '这是特别的类,几乎被很多开发者忽略,但是功能最简单,却是却实用的类, 06. ' The following events are available for MyApplication: 07. ' 08. ' Startup: Raised when the application starts, before the startup form is created. 09. ' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally. 10. ' UnhandledException: Raised if the application encounters an unhandled exception. 11. ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 12. ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected. 13. Partial Friend Class MyApplication 14. '检测计算是否接入网络 15. Private Sub MyApplication_NetworkAvailabilityChanged(sender As Object, e As Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs) Handles Me.NetworkAvailabilityChanged 16. SetConnectionStatus(e.IsNetworkAvailable) 17. End Sub 18. 19. '当应用程序各个窗体都关闭了。这个程序才运行,也是最后运行的程序 20. Private Sub MyApplication_Shutdown(sender As Object, e As System.EventArgs) Handles Me.Shutdown 21. MsgBox("程序已经关闭运行!") 22. End Sub 23. 24. '当应用程序最开始启动时就运行了。早于任何窗体,在这个地方来初始化变量是最好的 25. Private Sub MyApp_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup 26. ' When the application starts, set the connection status on the status strip 27. MsgBox("程序将要开始启动") 28. 29. End Sub 30. 31. Public Sub SetConnectionStatus(ByVal connected As Boolean) 32. 'With My.Forms.MainForm.ConnectedStatusLabel 33. ' If (connected) Then 34. ' .Image = My.Resources.connected.ToBitmap 35. ' .Text = My.Resources.ConnectedText 36. ' Else 37. ' .Image = My.Resources.disconnected.ToBitmap 38. ' .Text = My.Resources.DisconnectedText 39. ' End If 40. 'End With 41. End Sub 42. 43. Private Sub MyApplication_StartupNextInstance(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance 44. MsgBox("程序已经启动一次了") 45. End Sub 46. 47. '当程序在运行中出错,而未作处理时,它是来收集错误并提示错误内容 48. Private Sub MyApplication_UnhandledException(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException 49. MsgBox("程序在运行中出现错误") 50. End Sub 51. End Class 52. 53. 54.End Namespace