Relationships Between Forms
The Form class has two properties that control a form’s relationship to other forms: the Parent property (inherited from the Control class) and the Owner property. Setting the Parent property causes the constrained form to appear only within the bounds of the parent—and always to appear on top of the parent. This gives an effect similar to MDI applications (which have other features as well and are discussed later in this chapter). When a form has a parent, it can be docked to the parent’s edges, just like any other control. The code in Example 4-4 demonstrates this. It can be compiled from the command line with this command:
vbc filename.vb /r:System.dll,System.Drawing.dll,System.Windows.Forms.dll /t:winexeThe result is displayed in Figure 4-6.

Figure 4-6. A form with a parent
Example 4-4. Creating a form with a parent
Imports System.Drawing Imports System.Windows.Forms Module modMain <System.STAThreadAttribute( )> Public Sub Main( ) System.Threading.Thread.CurrentThread.ApartmentState = _ System.Threading.ApartmentState.STA System.Windows.Forms.Application.Run(New MyParentForm( )) End Sub End Module Public Class MyParentForm Inherits Form Public Sub New( ) ' Set my size. Me.ClientSize = New System.Drawing.Size(600, 400) ' Create and show a child form. Dim frm As New MyChildForm(Me) frm.Show( ) End Sub End Class Public Class MyChildForm Inherits Form ...