KEMBAR78
Complete-Reference-Vb Net 91 | PDF | Menu (Computing) | Software Development
0% found this document useful (0 votes)
21 views1 page

Complete-Reference-Vb Net 91

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views1 page

Complete-Reference-Vb Net 91

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Creating the MDI Children

event that causes something to happen in the application.


4. Save and build the form, which, at this point, is nothing more than an empty MDI application that
consists of nothing more than the main form. Build the form by selecting the project in Solution
Explorer, right−click to expose the context menus, and select Debug | Start New Instance. The
application will now run maximized as we had earlier set. The menus will not work, because we have
not wired up any code under them. But, you can close the application from the Close facility ("x" or
"Close Alt + F4") in the top−right or top−left corner, respectively.

Tip You may get a build error stating that the compiler could not find the entry point to the
application. That will happen if you change the class name in code from Class1 to something else
(VS is not updated when you change the name manually). It's an easy fix from the Properties
window, where you select the new name as the so−called WinMain entry point.

Creating the MDI Children

An MDI application would not be an MDI application without child forms, so you need to create the template
object that instantiates them. To do this, we will add a child form class to the MDI parent, which already has a
Window top−level menu item, as well as New and Close to create, close, and enumerate the child form
objects, respectively. Return to the drop−down list at the top of the Properties window and select the
&Window menu item. You can set its MDIList property to True.

This property provides the facility to enumerate the "handles" of open or created child windows, essentially
instantiated form objects, and maintain the list in the Window menu. You can also place a check mark next to
the active child window in this menu. To set this up, go to Solution Explorer, right−click the project name,
select Add, and then select Windows Form. This form serves as the template for all MDI child forms. In other
words, every time your user selects New from the menu, an instance of this form object will be created. To
create the child form in the designer, do as follows:

1. In Solution Explorer, select the name of the project, right−click, and select Add New Item. The Add
New Item dialog box appears.
2. Now select Local Project Items from the Categories pane and Windows Form from the Templates
pane to the right.
3. In the Name box, name the form Child.vb and click the Open button to add the form to the project.
The Windows Forms Designer adds another tab to the work area and displays "child" on the canvas.

You can now change the name of the class and its various properties, as we did earlier with the parent. I
named the class ChildForm (try to avoid giving the class the same name as the filesuch as dittoname.vb).You
can then also drag whatever controls and components you need onto the child form, thereby aggregating these
controls and components to the child class. You do not need to explicitly make the child class a child class,
because by default its IsMDIContainer property is set to False. After all, you can only have one parent MDI
container, and it's already been created.

But we do need to wire up the child class to the MDI parent. We can start the ball rolling by creating an event
handler under the New menu item we created earlier. To do that, simply double−click New in the parent form.
An event handler, just like the ones we studied in Chapter 14, is created and defined in the MDI parent class
with all the necessary event constructs.

Now we need to add some code to the event handler, which will create new MDI child forms whenever the
user clicks the New menu item. The following code handles the job of instantiating new child window objects.
As you write the method, you'll easily spot the correct class in the object browser that IntelliSense pops up
under your fingertips. It's a good thing we renamed it from Form1, because we can be sure we are referencing

575

You might also like