pemrograman visual

24
1 Multiple Document Interface (MDI) Windows

description

p Sdidanmdi

Transcript of pemrograman visual

Page 1: pemrograman visual

1

Multiple Document Interface (MDI) Windows

Page 2: pemrograman visual

Single Document Interface (SDI)• A program that can only support one open

window or a document • For Example, paint and Notepad are SDI’s• MDI programs enable users to edit multiple

documents at once.• For example, Photoshop and Adobe Acrobat

Reader are MDI’s

Multiple Document Interface (MDI) Windows

Page 3: pemrograman visual

Single Document Interface (SDI)

Multiple Document Interface (MDI)

Page 4: pemrograman visual

Cont.

• The application window of an MDI program is called the parent window.

• Each window inside the application is referred to as a child window.

Page 5: pemrograman visual

Cont…

• MDI– Allows multiple windows

• Parent window– Application window– Can have many child windows

• Child window– Cannot be parent– Has exactly one parent– Cannot be moved outside parent– Functionality can be different than other child windows from

same parent

Page 6: pemrograman visual

Cont.

Page 7: pemrograman visual

How to create and MDI form?

• To create and MDI form, create a new form and set its IsMDIContainer property to True. The form will then change appearance

Page 8: pemrograman visual

How to create a child?

• Next, create a child form class to be added to the form.

• To do this, right-click the project in the Solution Explorer, select Add Windows Form... and name the file.

Page 9: pemrograman visual

Cont.

• To add the child form to the parent, we must create a new child form object, set its MDIParent property to the parent form and call method Show:

Dim frmChild As New ChildFormClass()frmChild.MdiParent = frmParentfrmChild.Show()

Page 10: pemrograman visual

MDI Form events and properties

Description / Delegate and Event Arguments

Common MDI Child Properties

IsMdiChild Indicates whether the Form is an MDI child. If True, Form is an MDI child (read-only property).

MdiParent Specifies the MDI parent Form of the child.

Common MDI Parent Properties

ActiveMdiChild Returns the Form that is the currently active MDI child (returns Nothing if no children are active).

IsMdiContainer Indicates whether a Form can be an MDI parent. If True, the Form can be an MDI parent. The default value is False.

MdiChildren Returns the MDI children as an array of Forms.

Common Method

LayoutMdi Determines the display of child forms on an MDI parent. Takes as a parameter an MdiLayout enumeration with possible values ArrangeIcons, Cascade, TileHorizontal and TileVertical. Figure 13.36 depicts the effects of these values.

Common Event (Delegate EventHandler, event arguments EventArgs)

MdiChildActivate Generated when an MDI child is closed or activated.

Fig. 13.33 MDI parent and MDI child events and properties.

Page 11: pemrograman visual

Cont.

• Child windows can be minimized, maximized and closed independently of each other and of the parent window.

• When the parent is minimized or closed, the child windows are minimized or closed as well.

Page 12: pemrograman visual

Multiple Document Interface (MDI) Windows

Page 13: pemrograman visual

MdiList Property• VB .NET provides a property that facilitates

the tracking of which child windows are opened in an MDI container.

• Property MdiList (a Boolean) of class Menu- Item determines whether a MenuItem

displays a list of open child windows.• The list appears at the bottom of the menu

following a separator bar

Page 14: pemrograman visual

• When a new child window is opened, an entry is added to the list.

• If nine or more child windows are open, the list includes the option More Windows..., which allows the user to select a window from a list, using a scrollbar.

• Multiple MenuItems can have their MdiList property set; each displays a list of

open child windows.

MdiList Property

Page 15: pemrograman visual
Page 16: pemrograman visual
Page 17: pemrograman visual

LayoutMdi Property• MDI containers allow developers to organize

the placement of child windows. • The child windows in an MDI application can be

arranged by calling method LayoutMdi of the parent form.

• Method LayoutMdi takes a LayoutMdi enumeration, which can have values ArrangeIcons, Cascade, TileHorizontal and TileVertical.

Page 18: pemrograman visual
Page 19: pemrograman visual
Page 20: pemrograman visual

1 ' Fig. 13.37: UsingMDI.vb2 ' Demonstrating use of MDI parent and child windows.34 Public Class FrmUsingMDI5 Private childWindow as FrmChild6 ' create Child1 when menu clicked7 Private Sub mnuitmChild1_Click( _ 8 ByVal sender As System.Object, _9 ByVal e As System.EventArgs) Handles mnuitmChild1.Click10 11 ' create image path12 Dim imagePath As String = _13 Directory.GetCurrentDirectory() & "\images\image0.jpg"14 15 ' create new child16 childWindow = New FrmChild(imagePath, "Child1")17 childWindow.MdiParent = Me ' set parent18 childWindow.Show() ' display child19 End Sub ' mnuitmChild1_Click2021 ' create Child2 when menu clicked22 Private Sub mnuitmChild2_Click( _23 ByVal sender As System.Object, _24 ByVal e As System.EventArgs) Handles mnuitmChild2.Click

Page 21: pemrograman visual

25 ' create image path26 Dim imagePath As String = _27 Directory.GetCurrentDirectory() & "\images\image1.jpg"28 29 ' create new child30 childWindow = New FrmChild(imagePath, "Child2")31 childWindow.MdiParent = Me ' set parent32 childWindow.Show() ' display child33 End Sub ' mnuitmChild2_Click34 35 ' create Child3 when menu clicked36 Private Sub mnuitmChild3_Click( _37 ByVal sender As System.Object, _38 ByVal e As System.EventArgs) Handles mnuitmChild3.Click39 40 ' create image path41 Dim imagePath As String = _42 Directory.GetCurrentDirectory() & "\images\image2.jpg"43 ' create new child44 childWindow = New FrmChild(imagePath, "Child3")45 childWindow.MdiParent = Me ' set parent46 childWindow.Show() ' display child47 End Sub ' mnuitmChild3_Click

Page 22: pemrograman visual

48 ' exit application49 Private Sub mnuitmExit_Click(ByVal sender As System.Object, _50 ByVal e As System.EventArgs) Handles mnuitmExit.Click51 52 Application.Exit()53 End Sub ' mnuitmExit_Click55 54 ' set cascade layout55 Private Sub mnuitmCascade_Click(ByVal sender As System.Object, _56 ByVal e As System.EventArgs) Handles mnuitmCascade.Click57 58 Me.LayoutMdi(MdiLayout.Cascade)59 End Sub ' mnuitmCascade_Click60 61 ' set TileHorizontal layout62 Private Sub mnuitmTileHorizontal_Click( _63 ByVal sender As System.Object, ByVal e As System.EventArgs) _ 64 Handles mnuitmTileHorizontal.Click65 66 Me.LayoutMdi(MdiLayout.TileHorizontal)67 End Sub ' mnuitmTileHorizontal_Click

Method LayoutMdi can takevalues ArrangeIcons, Cascade,TileHorizontal and TileVertical

Page 23: pemrograman visual

68 ' set TileVertical layout69 Private Sub mnuitmTileVertical_Click( _70 ByVal sender As System.Object, _ 71 ByVal e As System.EventArgs) Handles mnuitmTileVertical.Click72 73 Me.LayoutMdi(MdiLayout.TileVertical)74 End Sub ' mnuitmTileVertical_Click75 76 End Class ' FrmUsingMDI

Page 24: pemrograman visual

Multiple Document Interface (MDI) Windows

Demo