
Normally when you write a code, you create procedures that you own code calls, as necessary. You create parameters and their types, and you determine the return value, if any. In an Event driven Environment, like windows, your application must be able to react to things that happens while the application runs. For example when a user clicks a button, or types of a key, your application may have to take a particular action. Think of these occurrences as “interesting things” happening in your application, that is, they are interesting in an application, at least:
Try this out:
Namespace My
' The following events are available for My Application Eventhandles:
'
' 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
My.Application.MinimumSplashScreenDisplayTime = 3000
#If Beta Then
My.Application.SplashScreen = My.Forms.SplashScreen2
#End If
Return MyBase.OnInitialize(commandLineArgs)
End Function
Private Sub MyApplication_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
My.Application.Log.WriteEntry( _
String.Format("Application shut down by {0} at {1:t}", _
My.User.Name, My.Computer.Clock.LocalTime), _
TraceEventType.Information)
End Sub
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
My.Application.Log.WriteEntry( _
String.Format("Application started by {0} at {1:t}", _
My.User.Name, My.Computer.Clock.LocalTime), _
TraceEventType.Information)
End Sub
Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
My.Application.Log.WriteException(e.Exception, _
TraceEventType.Critical, "Unhandled exception")
End Sub
End Class
End Namespace
Module Globals
Public Sub DisplayAlert(ByVal Text As String)
MessageBox.Show(Text, Application.ProductName, MessageBoxButtons.OK)
End Sub
End Module
Public NotInheritable Class SplashScreen2
'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 SplashScreen2_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
ApplicationTitle.Text = My.Application.Info.Title & " BETA"
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
End Class
Partial Public Class Switchboard
Inherits System.Windows.Forms.Form
_
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
End Sub
'Form overrides dispose to clean up the component list.
_
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
_
Private Sub InitializeComponent()
Me.MyApplicationButton = New System.Windows.Forms.Button
Me.MyComputerButton = New System.Windows.Forms.Button
Me.MyFormsButton = New System.Windows.Forms.Button
Me.MyResourcesButton = New System.Windows.Forms.Button
Me.MySettingsButton = New System.Windows.Forms.Button
Me.MyUserButton = New System.Windows.Forms.Button
Me.MyWebServicesButton = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'MyApplicationButton
'
Me.MyApplicationButton.Location = New System.Drawing.Point(12, 12)
Me.MyApplicationButton.Name = "MyApplicationButton"
Me.MyApplicationButton.Size = New System.Drawing.Size(165, 33)
Me.MyApplicationButton.TabIndex = 0
Me.MyApplicationButton.Text = "My.Application"
'
'MyComputerButton
'
Me.MyComputerButton.Location = New System.Drawing.Point(12, 50)
Me.MyComputerButton.Name = "MyComputerButton"
Me.MyComputerButton.Size = New System.Drawing.Size(165, 33)
Me.MyComputerButton.TabIndex = 1
Me.MyComputerButton.Text = "My.Computer"
'
'MyFormsButton
'
Me.MyFormsButton.Location = New System.Drawing.Point(12, 126)
Me.MyFormsButton.Name = "MyFormsButton"
Me.MyFormsButton.Size = New System.Drawing.Size(165, 33)
Me.MyFormsButton.TabIndex = 2
Me.MyFormsButton.Text = "My.Forms"
'
'MyResourcesButton
'
Me.MyResourcesButton.Location = New System.Drawing.Point(9, 164)
Me.MyResourcesButton.Name = "MyResourcesButton"
Me.MyResourcesButton.Size = New System.Drawing.Size(165, 33)
Me.MyResourcesButton.TabIndex = 3
Me.MyResourcesButton.Text = "My.Resources"
'
'MySettingsButton
'
Me.MySettingsButton.Location = New System.Drawing.Point(9, 202)
Me.MySettingsButton.Name = "MySettingsButton"
Me.MySettingsButton.Size = New System.Drawing.Size(165, 33)
Me.MySettingsButton.TabIndex = 4
Me.MySettingsButton.Text = "My.Settings"
'
'MyUserButton
'
Me.MyUserButton.Location = New System.Drawing.Point(12, 88)
Me.MyUserButton.Name = "MyUserButton"
Me.MyUserButton.Size = New System.Drawing.Size(165, 33)
Me.MyUserButton.TabIndex = 5
Me.MyUserButton.Text = "My.User"
'
'MyWebServicesButton
'
Me.MyWebServicesButton.Location = New System.Drawing.Point(12, 240)
Me.MyWebServicesButton.Name = "MyWebServicesButton"
Me.MyWebServicesButton.Size = New System.Drawing.Size(165, 33)
Me.MyWebServicesButton.TabIndex = 6
Me.MyWebServicesButton.Text = "My.WebServices"
'
'Switchboard
'
Me.ClientSize = New System.Drawing.Size(186, 284)
Me.Controls.Add(Me.MyWebServicesButton)
Me.Controls.Add(Me.MyUserButton)
Me.Controls.Add(Me.MySettingsButton)
Me.Controls.Add(Me.MyResourcesButton)
Me.Controls.Add(Me.MyFormsButton)
Me.Controls.Add(Me.MyComputerButton)
Me.Controls.Add(Me.MyApplicationButton)
Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "Switchboard"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Switchboard"
Me.ResumeLayout(False)
End Sub
Friend WithEvents MyApplicationButton As System.Windows.Forms.Button
Friend WithEvents MyComputerButton As System.Windows.Forms.Button
Friend WithEvents MyFormsButton As System.Windows.Forms.Button
Friend WithEvents MyResourcesButton As System.Windows.Forms.Button
Friend WithEvents MySettingsButton As System.Windows.Forms.Button
Friend WithEvents MyUserButton As System.Windows.Forms.Button
Friend WithEvents MyWebServicesButton As System.Windows.Forms.Button
End Class
Public Partial Class MyWebServicesForm
Inherits System.Windows.Forms.Form
_
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
End Sub
'Form overrides dispose to clean up the component list.
_
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
_
Private Sub InitializeComponent()
Me.NumbersButton = New System.Windows.Forms.Button
Me.NumberTextBox = New System.Windows.Forms.TextBox
Me.ResultsLabel = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'NumbersButton
'
Me.NumbersButton.Location = New System.Drawing.Point(12, 49)
Me.NumbersButton.Name = "NumbersButton"
Me.NumbersButton.Size = New System.Drawing.Size(324, 28)
Me.NumbersButton.TabIndex = 0
Me.NumbersButton.Text = "Convert number to text"
'
'NumberTextBox
'
Me.NumberTextBox.Location = New System.Drawing.Point(12, 12)
Me.NumberTextBox.Name = "NumberTextBox"
Me.NumberTextBox.Size = New System.Drawing.Size(85, 22)
Me.NumberTextBox.TabIndex = 1
Me.NumberTextBox.Text = "123.45"
'
'ResultsLabel
'
Me.ResultsLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.ResultsLabel.Location = New System.Drawing.Point(12, 87)
Me.ResultsLabel.Name = "ResultsLabel"
Me.ResultsLabel.Size = New System.Drawing.Size(413, 24)
Me.ResultsLabel.TabIndex = 2
Me.ResultsLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'MyWebServicesForm
'
Me.ClientSize = New System.Drawing.Size(440, 136)
Me.Controls.Add(Me.ResultsLabel)
Me.Controls.Add(Me.NumberTextBox)
Me.Controls.Add(Me.NumbersButton)
Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "MyWebServicesForm"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "My.WebServices"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents NumbersButton As System.Windows.Forms.Button
Friend WithEvents NumberTextBox As System.Windows.Forms.TextBox
Friend WithEvents ResultsLabel As System.Windows.Forms.Label
End Class
You must know we need all these included in the project:
obj\Debug\ResolveAssemblyReference.cache
obj\Debug\MyNamespace.Switchboard.resources
obj\Debug\MyNamespace.Resources.resources
obj\Debug\MyNamespace.vbproj.GenerateResource.Cache
obj\Debug\MyNamespace.LoginForm.resources
obj\Debug\MyNamespace.MyApplicationForm.resources
obj\Debug\MyNamespace.MyComputerClipboardForm.resources
obj\Debug\MyNamespace.MyForms1.resources
obj\Debug\MyNamespace.MyForms2.resources
obj\Debug\MyNamespace.MyForms3.resources
obj\Debug\MyNamespace.MyResourcesForm.resources
obj\Debug\MyNamespace.MySettingsForm.resources
obj\Debug\MyNamespace.MyUserForm.resources
***More to come...