multiple document interface (mdi) application

24
Multiple Document Interface (MDI) application Part 1

Upload: dyan

Post on 16-Jan-2016

85 views

Category:

Documents


8 download

DESCRIPTION

Multiple Document Interface (MDI) application. Part 1. Objectives. Understand the characteristics of MDI applications Organize the procedures between forms in MDI applications Understand the role of standard forms in an MDI application - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Multiple Document Interface (MDI) application

Multiple Document Interface (MDI) application

Part 1

Page 2: Multiple Document Interface (MDI) application

Objectives

• Understand the characteristics of MDI applications• Organize the procedures between forms in MDI

applications• Understand the role of standard forms in an MDI

application• Integrate menus in an MDI application and create

context menus• Understand the relationships between events in an MDI

application• Manage and organize the forms that make up an MDI

application

Page 3: Multiple Document Interface (MDI) application

Solution Organization

Page 4: Multiple Document Interface (MDI) application

Characteristics of MDI Programs

• Single-document interface applications– Create one instance of a particular form

• Multiple-document interface (MDI) applications– Create multiple instances of the same form– Display those multiple form instances such

that they appear inside the region of another form

• Excel is an MDI application, for example

Page 5: Multiple Document Interface (MDI) application

MDI Applications

• You can use three different types of forms in an MDI application– An MDI parent form acts as the container for the MDI

child forms in the solution

– An MDI child form always appears inside the visible region of its MDI parent form

• A project may have one or more MDI child forms

– Standard forms can be displayed anywhere on the screen and are not contained by the MDI parent form

• Standard forms are typically displayed as dialog boxes

Page 6: Multiple Document Interface (MDI) application

Characteristics of MDI Applications

• MDI child forms can not be extended beyond the visible region of the containing MDI parent form

• Iconified MDI child forms do not appear on the task bar– The user positions the icon inside the visible

region of the MDI parent form

• Menus of MDI parent and MDI child forms are integrated

Page 7: Multiple Document Interface (MDI) application

Displaying an MDI Child Form

• Code to create MDI child form appears in MDI parent form

• Create the child form instanceDim frmCurrentChild As New frmMdiChild()

• Designate the form as a child formfrmCurrentChild.MdiParent = Me

• Display the child formfrmCurrentChild.Show()

Page 8: Multiple Document Interface (MDI) application

Organizing Proceduresin MDI Applications (1)

• The following list describes the problems shared by nearly all MDI applications– Procedures and data must often be shared by

both MDI parent forms and MDI child forms

– An MDI parent form often needs to know which MDI child form instance is active

– From the MDI child form, you must often reference members of the MDI parent form or the MDI parent form itself

Page 9: Multiple Document Interface (MDI) application

Organizing Proceduresin MDI Applications (2)

• When organizing the procedures and variables in an MDI application, consider the following rules– Locate the procedures that create instances of the

MDI child forms in the MDI parent form– In the MDI child form(s), create the procedures

responsible for managing each instance of the MDI child form

– To share a global reference to the MDI parent form, declare a Friend or global variable in a module file

• When the MDI parent form loads, store a reference to the MDI parent form in the Friend or global variable

Page 10: Multiple Document Interface (MDI) application

Standard Forms in MDI Applications

• MDI applications can have standard forms

• Characteristics– Standard forms typically do not have menus– Standard forms are typically displayed as

modal dialog boxes

Page 11: Multiple Document Interface (MDI) application

Menus and MDI Applications

• Each MDI parent form and any MDI child form in a solution can have its own menu system

• MDI application menus have unique characteristics– One menu bar appears below the title bar of the MDI

parent form– An MDI parent form’s menu appears when no MDI child

forms are loaded– When an instance of an MDI child form is loaded or has

focus, the menu of the MDI parent form is merged with the menu of the MDI child form

– Standard forms in an MDI application can have an associated menu but typically they do not

Page 12: Multiple Document Interface (MDI) application

Merging Menus

• Menus of MDI parent and MDI child forms are merged based on the following property values:

• MergeOrder property– Applies to a MenuItem and contains an Integer value– Indicates the relative order in which two menus or

menu items will be merged

• MergeType property – Works in conjunction with the MergeOrder property – Defines whether one menu will replace another menu,

whether one menu will be added to another menu, or whether menu items will be merged together

Page 13: Multiple Document Interface (MDI) application

The MergeType Property

• The MergeType property has a data type of MenuMerge

• Possible enumeration values– Add - menu on the MDI child form will be added to the

menu of the MDI parent form– MergeItems - menu items on the MDI child form menu

will be merged with the menu items on the MDI parent form menu

– Remove - MDI parent form menu or menu item will not appear in the merged menu

– Replace - causes the menu of the MDI child form to replace the menu appearing on the MDI parent form

Page 14: Multiple Document Interface (MDI) application

Merging Menus (1)

Page 15: Multiple Document Interface (MDI) application

Merging Menus (2)

Page 16: Multiple Document Interface (MDI) application

Merging Menus (3)

Page 17: Multiple Document Interface (MDI) application

Using Menus to Select MDI Child Forms

• To select and display an MDI child form from a menu– Set the MdiList property of a menu item to True

• This setting causes the menu item to display a list of MDI child form instances

• The caption appearing in the menu is the same as the caption appearing in the title bar of the MDI child form

• The process is automatic - you need not write any statements to display the MDI child forms

Page 18: Multiple Document Interface (MDI) application

Arranging MDI Child Forms

• The LayoutMdi method applies to the MDI parent form– Use to configure display of child forms

• Four valid enumeration values– ArrangeIcons - iconified MDI child windows are

arranged along the bottom of the MDI parent form– Cascade - visible MDI child windows are arranged

such that each MDI child window appears below another MDI child window and is indented

– TileHorizontal - divides the MDI child forms horizontally to fill the visible region of the MDI parent form

– TileVertical - divides the MDI child forms vertically to fill the visible region of the MDI parent form

Page 19: Multiple Document Interface (MDI) application

Context Menus

• Context menus typically appear when the user right-clicks on a control instance or the form itself

• To create a context menu:– Create an instance of the ContextMenu control– Create the menu items in-place– Associate the context menu with a form or

control instance by setting the ContextMenu property of the desired form or control instance to the context menu

Page 20: Multiple Document Interface (MDI) application

Context Menus (Illustration)

Menu items

Context menu title cannot be changed

Page 21: Multiple Document Interface (MDI) application

MDI Event Relationships

• Windows fires various events as the user navigates from form to form in an MDI application

• Events – The Closing event fires for both the MDI parent and MDI

child forms• Fires first for all children and then the parent• Event can be cancelled

– The Enter event fires for the MDI child form getting focus• Use to update status information

– The Leave event fires just before an instance of the MDI child form loses focus

Page 22: Multiple Document Interface (MDI) application

Order of Closing Events

Page 23: Multiple Document Interface (MDI) application

Managing MDI Child Forms

• There is no Forms collection to manage the loaded MDI forms of an application

• Create a class to enable the developer to add and remove forms from the collection, and enumerate the collection with a For Each loop

Page 24: Multiple Document Interface (MDI) application

Summary• MDI application consists of

– MDI form and multiple MDI child forms• Child forms

– Can be multiple instances of the same class, or each child can be an instance of different classes

• Basics of building an MDI application– Designate one form as an MDI form by setting its IsMdiContainer

property to True– Add another form (Form2) to the project, which becomes a child

form– Because the form is defined as a class, the (parent) MDI form

must instantiate a new (child) form2 (Form2Temp)– Declare Form2Temp’s MdiParent property to be the MDI form

itself– Finally, show Form2Temp