Skip to Content
Programming Visual Basic .NET
book

Programming Visual Basic .NET

by Dave Grundgeiger
December 2001
Beginner
464 pages
13h 51m
English
O'Reilly Media, Inc.
Content preview from Programming Visual Basic .NET

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:winexe

The result is displayed in Figure 4-6.

A form with a parent

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Visual Basic .NET, Second Edition

Programming Visual Basic .NET, Second Edition

Jesse Liberty

Publisher Resources

ISBN: 0596000936Supplemental ContentCatalog PageErrata