![]() ![]() | ||
You can also create owned forms in Visual Basic. An owned form is tied to the form that owns it; if the user minimizes the owner form, the owned form will also be minimized, and so on. You can add an owned form with the AddOwnedForm method, and remove an owned form with the RemoveOwnedForm method. Here's an example called OwnedForms on the CD-ROM. In this case, I'll place a button in Form1 that will make an object of the Form2 class into an owned form and display it:
Public Class Form1 Inherits System.Windows.Forms.Form Dim OwnedForm1 As New Form2() 'Windows Form Designer generated code Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Me.AddOwnedForm(OwnedForm1) OwnedForm1.Show() End Sub End Class
You can see the results in Figure 4.21, where I've placed a label with the text "This is an owned form" in the owned form.
![]() ![]() | ||