' Project FormEvents, source code file frm1.vb. ' Illustrate some of the form events. ' Note that a non-startup form must ' be explicitly created as an object. Public Class frmA Inherits System.Windows.Forms.Form Public Shared a As frmA, b As frmB #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Friend WithEvents txtMsg As System.Windows.Forms.TextBox 'Required by the Windows Form Designer Private components As System.ComponentModel.Container '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. Friend WithEvents btnShowB As System.Windows.Forms.Button Private Sub InitializeComponent() Me.txtMsg = New System.Windows.Forms.TextBox Me.btnShowB = New System.Windows.Forms.Button Me.SuspendLayout() ' 'txtMsg ' Me.txtMsg.Location = New System.Drawing.Point(24, 72) Me.txtMsg.Name = "txtMsg" Me.txtMsg.Size = New System.Drawing.Size(200, 26) Me.txtMsg.TabIndex = 1 Me.txtMsg.Text = "" ' 'btnShowB ' Me.btnShowB.Location = New System.Drawing.Point(24, 24) Me.btnShowB.Name = "btnShowB" Me.btnShowB.Size = New System.Drawing.Size(200, 32) Me.btnShowB.TabIndex = 0 Me.btnShowB.Text = "Show frmB" ' 'frmA ' Me.AutoScaleBaseSize = New System.Drawing.Size(8, 19) Me.ClientSize = New System.Drawing.Size(248, 117) Me.Controls.Add(Me.txtMsg) Me.Controls.Add(Me.btnShowB) Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Name = "frmA" Me.Text = "frmA" Me.ResumeLayout(False) End Sub #End Region Private Sub frmA_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load MsgBox("Load Event for a") a = Me b = New frmB End Sub Private Sub frmA_Activated(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Activated txtMsg.Text = "Activated Event for a" End Sub Private Sub frmA_Deactivate(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Deactivate txtMsg.Text = "Deactivate Event for a" End Sub Private Sub frmA_Closed(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Closed MsgBox("Closed Event for a") End Sub Private Sub frmA_Closing(ByVal sender As Object, _ ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing MsgBox("Closing Event for a") End Sub Private Sub btnShowB_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnShowB.Click b.Show() End Sub End Class