Vous êtes sur la page 1sur 14

KHEC II/II

Visual Programming (BEG275CO) - 1 -

CHAPTER FIVE 5.0 ADVANCED INTERFACE DESIGNING CONTROLS:


5.1 COMMON DIALOG CONTROL: The common dialog control provides the standard set of dialog boxes such as opening and saving files, setting print options and selecting controls and fonts. Common dialog control can be used in the application by adding it from components of project menu and selecting common dialog control 6.0 and setting its properties. Then a new object is seen in the toolbox and this is added to the form for further processing. The dialog displayed by the control is determined by the methods of control. At run time the dialog box is displayed when the appropriate method is invoked. At design time the common dialog control is displayed as an icon in the form. It provides its services to the application but it doesn't need to be displayed on the form at runtime. The common dialog control allows displaying the following commonly used dialog boxes open, save as, color, font, print. Method Value Dialog displayed Showopen 1 Open Showsave 2 Save as Showcolor 3 Color Showfont 4 Font Showprinter 5 Print Showhelp 6 Invokes windows help
5.1.1 FILE OPEN DIALOG:

The open dialog box allows the user to specify a drives directory, a filename and a filename extension. At run time when the user chooses a file and closes the dialog box the filename property is used to get the selected filename. To display the open dialog box Private sub cmdopen_click() Commondialog1.showopen Commondialog1.filter="all files (*.*) | *.*| text files (*.txt)|*.txt| batch files (*.bat)" Commondialog1.filterindex = 0 End sub

Compiled By: Er. SRB

KHEC II/II

Visual Programming (BEG275CO) - 2 -

5.1.2 FILE SAVE AS DIALOG:

This dialog displays a window for saving the file in appropriate directory of a certain drive. e.g.: commondialog1.filter="text files|*.txt| batch files |*.bat| INI files|*.INI" commondialog1.filterindex=1 commondialog1.action=2 (or commondialog1.showsave) End sub
5.1.3 COLOR DIALOG:

This dialog allows the user to select a color from a palate or to create and select a custom color. To display color dialog box: Private sub commnad1_click() Commondialog1.showcolor Form1.backcolor=commondialog1.color End sub Font Dialog Box: This allows user to select a font by its size, color and style. Once user makes a selection in the font dialog box, the following properties contain the information about the user's selection. Property Determines Color Determines the selected color. To use this property you must first set the flag property (CdlCFEffects) FontBold Whether Bold was selected. FontItallic Whether italic was selected. FontStrikethru It's true if the strikethrough attribute is set. FontUnderline For underlined text FontName The selected font name FontSize Returns the selected font's size E.g.: Private sub command1_click() Commondialog1.flags=CdlCFBoth {sets the flag property. It can be either .CdlCFScreen Fonts (for Screen font) .CdlCFPrinter Fonts (for Printer font) .CdlCFBoth (for Both)} Commondialog1.showfont (display the font dialog box) Text1.font.name=commondialog1.fontname (sets text properties according to the users selection) Text1.font.sizename=commondialog1.fontsize Text1.font.bold=commondialog1.fontbold Text1.font.itallic=commondialog1.fontitallic Text1.font.underline=commondialog1.fontunderline Text1.Font.Strikethrou = CommonDialog1.FontStrikethru Text1.font.color=commondialog1.color End sub

Printer Dialog Box: This dialog allows user to specify how O/P should be printed. The user can specify a range of pages to be printed, a print quality, a no. of copies and so on. This dialog displays information about the currently installed printer. This dialog box only allows user to specify the way of data printing but never print the data. Necessary code is required for printing them. e.g.:
Compiled By: Er. SRB

KHEC II/II

Visual Programming (BEG275CO) - 3 -

private sub command1_click() dim startpage, endpage, numberofcopies ' displays the print dialog box Commondialog1.showprinter 'get user selected values from the dialog box Startpage=commondialog1.frompage Endpage=commondialog1.topage Numberofcopies=commondialog1.copies End sub 5.1.4 Help Dialog: This dialog displays the help dialog box and allows to display the help file. e.g.: Private sub command1_click() Commondialog1.showhelp Commondialog1.helpfile="path" End sub 5.2 WORKING WITH CONTROL ARRAYS: A control array is an array of controls i.e. a control array is a group of controls that share the same name and type. They also share the same event procedure. A control array has at least one element and can grow to as man elements as the system supports. The maximum index that can be used in the control array is 32767. Elements of the same control array have their own property settings and control arrays are used in menu control and option but on groupings. The advantages of using control with control arrays is that they need less resources than simply adding multiple controls of the same type to a form at design time. They are also useful if you want several controls to share code. At runtime, if the user creates a control, then that control must be member of a control array. With a control array, each new element inherits the common event procedure of the array. CREATING A CONTROL ARRAY: There are three ways of creating a control array at design time. i) By assigning the same name to more than one control. ii) By copying an existing control and then pasting it onto the form. iii) By setting the index property to a value that is not null. Adding and Removing a Control Array at Runtime: User can add and remove controls in a control array run time using the load and unload statements. However, the control to be added must be an element of an existing control array. User must have created a control at design time with the index property set, preferably to 0. Then, at run time, user can use this syntax. Argument Description Object Name of the control to add or to delete from the control array Index % The control's index value in the array Draw the following design

Private sub text1_gotfocus(index as integer) Text1(0).text="Ram" Text1(1).text="VB"


Compiled By: Er. SRB

KHEC II/II

Visual Programming (BEG275CO) - 4 -

Text1(2).text="9841454545" End sub 5.3 CREATING MENUS FOR PROGRAM: VB provides a feature that increases the functionality of an application by adding the menu bar i.e. VB application can be enhanced by adding menus to it. It offers convenient and consistent way to group commands easy way for users to access them. The menu bar appears below the title bar and it may contain one or many menus (titles). When a menu title is clicked, it displays the set of menu items under that title and its drop down. Each menu item corresponds to a menu control that is defined in a menu editor and performs a specific action. Once these menus are created they can be individually programmed to respond when selected. For designing the menu select from tool menu, the menu editor and design accordingly in the appeared window by giving appropriate name and caption with required access key or shortcut key.

Menu Properties: Menus are controls whose appearance and behavior can be changed and manipulated through its properties. These properties are displayed constantly in the menu editor window itself and can be set at design time using the menu editor dialog box or at run time from within code. Property Description Name Caption The text of the menu that the user will see. Name The name that is used to code to refer to the menu item and to identify the event code for each menu item. Index Used to form menu control arrays. This is where more than one menu item has the same name property and a number in the indexed property is used to address each item. Shortcut The menu can be invoked either by clicking it with the mouse in a normal way or by pressing the shortcut key. For e.g. Ctrl+X for cut operation. Windowlist This is used in multiple document interface (MDI) applications. This property tells VB to display the captions of the child window in the menu item. Checked Setting it to true causes a tick or check mark to appear beside the menu item. This is best for lists of options. Enabled Setting it to true allows user to select the menu item. Setting it to false causes the menu item to appear the gray out i.e. user can't select it. Visible Setting it to true causes the menu item to be visible at run time, clearing the check box makes it visible Negotiate Controls where, if at all, the menu appears when dealing with embedded ActiveX objects
Compiled By: Er. SRB

KHEC II/II

Visual Programming (BEG275CO) - 5 -

Position Menu Separator: A separation bar is a line that is used to break the item into a logical sequence which is useful for obtaining clarity. Separators are just as easy to create as any other menu items. Simply enter the menu item's caption as the character dash (-) and a dummy name such as mnudash1 as the name property. VB automatically interprets a menu item with a dash line as a separator line i.e. caption as '-' and name as mnudash1.
5.3.2 ADDING SHORTCUT AND ACCESS KEYS TO MENU ITEMS:

Keyboard access to menu can be improved to menu controls by defining access keys and shortcut keys. ACCESS KEYS: Access keys allow the user to open a menu pressing the Alt key and typing designated letter. Once a menu is opened, the user can choose a control by pressing the letter assigned to it. For e.g. Alt +F for file menu. Access key assignments appear as an underlined letter in the menu controls caption. To assign an access key to a menu control in the menu editor. i) Select the menu item to which you want to assign an access key. ii) In the caption box type an ampersand (&) immediately in front of the letter that you want as the access key. SHORT CUT KEYS: Shortcut key run a menu item immediately when pressed. Frequently used menu items may be assigned a keyboard shortcut which provides a single set method of keyboard access, rather than a three step method of pressing Alt, menu title access character and the menu item access character. Shortcut key assignments include function key and control key combinations such as Ctrl+F, Ctrl+A, Ctrl+C etc. They appear on the menu to the right of the corresponding menu item. To assign a shortcut key to a menu item i) Open a menu editor. ii) Select the menu item iii) Select the function key or key combination in the shortcut combo box.

5.3.3 CREATING AND ACCESSING POP UP MENUS:

A pop up menu is a floating menu that is displayed over a form independent of the menu bar. The class displayed in the pop up menu depends on where the pointer was located when the right mouse button was pressed. So, pop up menu are also called context menus. Pop up menus are used to provide an efficient method for accessing common contextual commands.
Compiled By: Er. SRB

KHEC II/II

Visual Programming (BEG275CO) - 6 -

To create a pop up menu, the same steps for creating the main menu in menu editor is followed with one extra step i.e. the pop-up menu should be hidden, so that it does not appear on the menu Bar. To hide the menu, set the visible property of the top-level menu item to false. Any menu that has at least one menu item can be displayed at runtime as a pop up menu. To display a pop up menu the PopUpMenu method is used. This method uses the following way of declaration. Object.PopupMenu menuname [flags, x, y, boldcommand] E.g.: Private sub form_mouseup(Button as integer, shift as integer, x as single, y as single) If button=2 then Popupmenu mnufile End if End sub i) Flag Arguments: These are used to further defining the location and behavior of a pop up menu. Location Constants Description VbPopupMenuLeftAlign Default. The specified X location defines the left edge of the pop-up menu. VbPopupMenuCenterAlign Pop-up menus is centered around the specified X location. VbPopupMenuRightAlign Specified X location defines the right of the pop-up menu. Behaviour Constant VbPopupMenuLeftButton VbPopupMenuRightButton Description Default. The pop-menu recognizes when the user clicks a menu item with the left mouse button only. The pop-menu recognizes when the user clicks the menu item with either the right or left mouse button.

e.g.: Private sub command1_click() Dim xloc, yloc Xloc=scalewidth/2 Yloc=scalewidth/2 Popupmenu mnuedit,VBPopUpMenuCenterAlign (or Popupmenu mnuedit, VBPopUpMenuRightButton, xloc, yloc) End sub ii) X & Y Arguments: Used to specify the X-Y coordinates where the pop-menu will be displayed. iii) Bold Command Arguments: Used to specify the name of a menu control which must appear in bold in the pop-up menu. Only one menu control in the pop-up menu can be bold.
5.3.4 MODIFYING MENUS AT RUN TIME:

At design time menus you have created are displayed on the form when you close the menu editor. Choosing a menu item on the form displays the click event procedure for that menu control where the required coding is written. The menus created at design time can also respond dynamically, to runtime conditions. For e.g. if a menu item action becomes inappropriate at some point, then the programmer can prevent users from selecting that menu item by disabling it. Programmer can also design the application to use a checkmarks to indicate which of the several commands was last selected. For e.g. the font's menu item from the application displays a submenu with a check mark next to the last font size selected.
Compiled By: Er. SRB

KHEC II/II

Visual Programming (BEG275CO) - 7 -

Enabling & Disabling Menu Commands:

E.g. mnufl(3).enabled=true/false (control array) mnufl.enabled=true/false


Displaying a checkmark on a menu control:

Using check property you can place a check mark on your menu. i) Tells the user the status of an on/off condition. Choosing the menu command alternatively adds and removes the check mark. ii) Indicate which of several modes is in effect. The settings menu of the text editor uses a check mark to indicate the current front size.
Making a menu control invisible:

E.g.: Mnflarray(0).visible=true/false
Adding Menu Control at Runtime:

A menu can grow at runtime. Control array is used to create a menu at runtime. For e.g. if have created a menu as mnflarray then this menu control is assigned a value for the index property at design time; it automatically becomes an element of control array even though no other elements have yet been created. When you create a mnflarray(0), you actually create separator bar that is invisible at runtime. The first time a user opens a file at run time, the separator bar becomes visible, and the first file name is added to the menu. And each time you open a file at runtime, addition menu controls are loaded into the array, making the menu grow. 5.4 WORKING WITH ACTIVEX CONTROLS (MICROSOFT WINDOWS COMMON CONTROLS):
5.4.1 TREE VIEW CONTROL:

A tree view control is used to display information within a tree hierarchy. A tree view is made up of nodes that are related to each other in some ways. Typically tree view control is used to display the headings in documents, entries in an index, the files and directories in a disk etc. The tree view is added to the toolbox from selecting project menu and then from components selects the Microsoft windows common control 6.0 then it is placed on the form for further operation. A tree view control displays a hierarchical list of node objects, each of which consists of a label and an optional bitmap. After creating a tree view control, one can add, remove, arrange and otherwise manipulate node objects by setting properties and invoking methods. Nodes can be expanded or collapsed to display or hide all child nodes according to the requirement. Three events, the collapse, expand and node click event also provide programming functionality.
ADDING NEW ITEMS:

The items or nodes on a tree view control are members of the nodes collection. The following is used to access the nodes collection. Treeview1.nodes The following are the methods and properties of the nodes collection Add Method: to add a new node to the nodes collection Count Property: returns the member of nodes in the nodes collection Clear Method: to remove all the nodes from the collection Item Property: to retrieve a node specified by an index value or a key. Remove Method: to remove a node from the nodes collection.

Compiled By: Er. SRB

KHEC II/II

Visual Programming (BEG275CO) - 8 -

To add a new node with the add method then you must specify its position in the hierarchy, the node text, its key, an image that will be displayed in front of the node and an image that will be displayed when the node is selected. The syntax for add method is Node.add relative, relationship, key, text image, selected image Here first argument is the key of the node, under which a new node is placed. The second argument indicates the relationship between the node specified in first argument and new node, the fifth argument is the text of the node.

Private sub cmdadd_click() Treeview1.nodes.add, , "FRUIT", "fruits" Treeview1.nodes.add, , "COLOR", "colors" Treeview1.nodes.add, , "SAPE", "shapes" Treeview1.linesytle=TVWRootlines End sub Here the line style determines the appearance of the line that connects nodes in a tree. Line style can have two values, 0 (tvwtreelines) and 1 (tvwrootlines). If line style is 0 then there will be line connecting parents to children and children to each other. If line style is 1 there will be lines connecting the root nodes. Private sub cmdfrt_click() Treeview1.nodes.add "FRUIT", tvwchild, , "apple" Treeview1.nodes.add "FRUIT", tvwchild, , "grapes" Treeview1.nodes.add "FRUIT", tvwchild, , "pineapple" End sub Private sub cmdclr_click() Treeview1.nodes.add "COLOR", tvwchild, , "red" Treeview1.nodes.add "COLOR", tvwchild, , "green" Treeview1.nodes.add "COLOR", tvwchild, , "blue" End sub Adding a parent property: As seen in the window explorer, the child nodes have tree lines in front of them, but their parents have the plus sign which indicates that a node has a child and can be expanded. E.g.: in above program Private sub cmdadd_click() Treeview1.nodes.add, , "SAMPLE","sample" (Displays all the nodes under a header called items) Treeview1.nodes.add " SAMPLE", tvwchild," FRUIT", "fruits" Treeview1.nodes.add " SAMPLE", tvwchild," COLOR", "colors" Treeview1.nodes.add " SAMPLE", tvwchild," SHAPE", "shapes" Here the first argument is the key of the parent node and their second argument add the first level items. Treeview1.nodes.item(" sample").expanded=true
Compiled By: Er. SRB

KHEC II/II

Visual Programming (BEG275CO) - 9 -

(for expanding the item node from code)


5.4.2 TOOLBAR CONTROL:

Toolbars provide the users an easy way to access the most commonly used functions of the program. A toolbar contains buttons that corresponds to items in an application menu providing a graphic interface for the user to access an application most frequently used functions and commands. A toolbar control and an image list control are used to add a toolbar to the form. The image list control contains a collection of bitmaps for use by other controls and the toolbars control uses images from the image list control to display them on its button. Toolbar control is added in the toolbox from project menu and then selecting components and then selects Microsoft window common control 6.0. The toolbar enables programmer to create 6 different types buttons as i) Push button: works like command button i.e. 0-tbrdefault e.g. save button in word. ii) Check button: works in an on/off mode i.e. 1-tbrcheck e.g. bold in word. iii) Button group: work like option buttons i.e. 2-tbrbuttongroup e.g. alignment button in word. iv) Separator: create empty spaces i.e. 3-tbrseparator v) Place holder: create empty space allowing one to place other controls such as combo box i.e. 4tbrplace holder e.g. font combo box in word. vi) Drop down buttons: when clicked offer the user a drop down menu of choices i.e. 5-tbrdropdown e.g. add from location in VB. For e.g. i) Add image list control on the form. Then to add bitmap image to the control press the ellipsis () button of the custom property in the properties window. ii) Then from image tab add images and then click on insert picture button and then click on ok button. iii) Draw the toolbar control on the menu and set the toolbar's alignment to none, top, bottom, left, or right accordingly. iv) Right click on the tool bar control and choose properties. v) Then create buttons on the toolbar from buttons tab and then click on insert button command button.

For each button specify the following properties as seen in above fig: Caption: this text is displayed beneath the picture on a button. Description: this text describes the button on the users when they invoke the customize toolbar dialog box.
Compiled By: Er. SRB

KHEC II/II

Visual Programming (BEG275CO) - 10 -

Key: this property specifies a string that is used to identify the button in code. Image: this property specifies the index of the picture that you want to appear on the face of the button. It corresponds to the index of the picture in the imagelist control specified in the general tab. Zero can be specified for the image property if you do not want a picture to appear on the button. Style: this property determines the type of button that you create. Tooltiptext: this text appears when the mouse pointer rests on the button. This text is displayed only if shoe tips property is set to true. Value: this property set or returns the current state of the button. A value of 0 indicates that the button is not pressed. A value of 1 indicates that the button is pressed. vi) Then insert button command is clicked to add the buttons and then press ok. For e.g. Place a toolbar and an image list on the form as shown below

Then in follow the above mentioned procedures. To display the image on the button give the image no. the same value that is given while inserting the image on the image list. Then double click on the toolbar and code as. Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) Text3.Text = Val(Text1.Text) + Val(Text2.Text) End Sub This will display the sum of entered two nos.
5.4.3 STATUS BAR CONTROL:

A status bar is a control that is displayed at the bottom of an application window unless its alignment is mentioned and displays information about the current state of the application. The status bar control can display and update certain types of information automatically. Set the style property to display the following Keyboard status for the caps lock, num lock, insert and scroll lock keys. Date Time The status bar can also contain text and bitmaps so that the message can also be displayed from the application in the status bar by using text property. Draw the status bar on the form. The status bar spans i) The widths of its parent form and contain a single panel. A status bar is broken into panel objects each of which displays different types of information. The panel collection of the status bar contains all the panel objects. The appearance and purpose of each panel is determined by the style property of that panel.
Compiled By: Er. SRB

KHEC II/II

Visual Programming (BEG275CO) - 11 -

ii)

Then right click on status bar and select properties. Then adjust the style and simple text properties of the status bar. These properties determine the appearance of the control at the runtime. The style property can have one of the two values simple or normal. Simple: when the style property is simple, only one panel of the status bar is visible, and the text is displayed in the simple text property. Normal: the toolbar appears with multiple panels.

Further control over the appearance of a status bar is done by setting properties from the panel tab for the property pages like sbrtext(0), sbrcaps(1), sbrnum(2), sbrins(3), sbrscrl(4), sbrline(5), sbrdate(6) etc. The syntax for adding panels in the status bar using the add method at the runtime is Statusbar1.panels.add (index, key, text, style, picture) i.e. private sub form_load() statusbar1.panels.add 1 , , "sample text", sbrtext statusbar1.panels.add , , , sbrnum end sub The syntax for removing a panel object is Stautsbar1.panels.remove index i.e. private sub form _load() statusbar1.panels.add 1 , , "sample text", sbrtext statusbar1.panels.add , , , sbrnum statusbar1.panels.remove 1 end sub
5.4.5 IMAGE LIST CONTROL:

The image list control is basically list of images but instead of storing only a single picture, the image list stores a collection of pictures. The image list control does not contain anything visible at run time; it is merely a storage area for the image. It is an ActiveX control that loads and stores group of images for use by other controls. The image list control maintains a series of images in its memory that other controls and quickly access at run time. i) Add the image list control on the form. ii) To add image to the control, press the ellipsis () button of the custom property in the properties window. iii) Then from images tab of appeared window add images and then click on insert picture button and click on ok. At runtime, image list can be accessed as Imagelist1.add, , loadpicture("path") For e.g. place an imagelist and a timer on the form and code as Private Sub Form_Load() Call Randomize Timer1.Interval = 500 End Sub Private Sub Timer1_Timer() Dim r As Integer r = Int(6 * Rnd()) + 1 Form1.Refresh
Compiled By: Er. SRB

KHEC II/II

Visual Programming (BEG275CO) - 12 -

Call PaintPicture(ImageList1.ListImages(r).Picture, Rnd() * Width, Rnd() * Height) End Sub This will display the added images from the imagelist on the form randomly.
5.4.4 PROGRESS BAR CONTROL:

This control shows the progress of a lengthy operation by filling a rectangle with chunks from left to right. This control doesn't always indicate how many minutes or seconds it will take the computer to perform given task but it provides the visual feedback necessary to convince the user that their transaction has not ground to halt or locked up the computer. This control has a range and a current position. Range represents the entire duration of operation and the current position represents the progress made towards completing the operations. Design the following interface and code as:

Private sub cmdsm_click() Dim I as integer Progressbar1.min=0 Progressbar1.max=10000 Progressbar1.visible=true For i=0 to 10000 Progressbar1.value=i Next i Progressbar1.visible=false Progressbar1.min=0 Txtres.text=val(txtnm1.text)+val(txtnm2.text) End sub Private sub form_load() Progressbar1.visible=false End sub 5.5 INTERFACE
5.5.1 SINGLE DOCUMENT INTERFACE (SDI):

The application that displays only one document at a time is called SDI. When an SDI application is executed, it can only display one document at a time. To edit multiple documents simultaneously user must execute another instance of document. Application containing only one form with various objects in VB is the example of single document interface. A project in VB may contain no. of forms but these forms can be run one at a time while the others can't be accessed at the same time, they remain unloaded.
5.5.2 MULTIPLE DOCUMENT INTERFACE:

When an application is designed, it might contain a no. of forms and each of these forms are displayed separately on the screen and moved, maximized or minimized separately from any other form. These forms can be organized as a group using MDI. The MDI is another class of the form object that allows us to open windows with in a parent container window. E.g. Microsoft word or excel have multiple document interface. An MDI application allows to display multiple documents at the same time with each document displayed in its own window. Document windows are contained in a parent window in application. Any application can have only one MDI
Compiled By: Er. SRB

KHEC II/II

Visual Programming (BEG275CO) - 13 -

form which contains all the application's child forms. At runtime, child forms are displayed within the interval area of the MDI form. Design time features of MDI child forms: At design time, child forms are not restricted to the area inside the parent form. You can add controls, set properties, write codes and design the features of child forms anywhere on the desktop. One can determine whether a form is a child by examining the project window. The project window uses special icons to distinguish standard forms, MDI child forms and MDI parent forms. Run time features of MDI child forms: At run time all child forms are displayed within the parent forms internal area. The user can move and size child form only within the internal area of the parent form. When a child is minimized, its icon appears on the MDI parent form instead of users desktop. When the parent form is minimized the entire application is represented by a single icon when restored all forms are re-displayed as they were. When a child form is maximized its caption is combined with parents' forms caption and displayed in the parent title bar. By setting the 'autoshowchildren' property, one can display child forms automatically, when forms are loaded. New child forms can be created at runtime using a special form of the dim statement. The parent form 'activeform' property indicates which child form is currently active. The 'active control' property indicates which control on the active child form has focused. MDI form has all the properties similar to general form. So one can add picture, buttons on the form for easier accessing of the data in the application. The arrange command can be used to determine how the child forms and their icons are displayed. To create an MDI application, at least two forms are needed in the application. One is the parent or container form and the second is the child or the form contained with the parent. To have more than one type of child form you can add further forms to the project. Only a single child form is required for the simple MDI projects. To create MDI form: From project menu, choose add MDI form. To create the application's child forms: From project menu, choose Add from to create a new form or open an existing form and set its MDIchild property to true. e.g.: i) Open VB in standard exe and change the caption of form to child form. ii) By right clicking on the forms folder in the project explorer add the MDI form by selecting Add MDI form dialog. iii) Change the caption of MDI to MDI parent. iv) Right click on project1 in the project explorer and select project1 properties from the pop up menu. Set the startup object list to MDI form. v) Select the child form from project explorer and set the form's MDI child property to true in the project window. This will cause this form which is the child, to rest inside the MDI parent container. vi) Run and see the O/p. For example we have two child forms, out of which one is used to calculate the sum of entered two numbers and another form displays the upper case of entered lower case letters. These forms can be displayed in MDI form by following the above mentioned process. Beside this, menu can also be added on the MDI form as shown below. This program firstly displays two child forms on MDI form and selecting each from menu shows only the selected form on the MDI form.

Compiled By: Er. SRB

KHEC II/II

Visual Programming (BEG275CO) - 14 -

Code for child1 form Private Sub Cmdsm_Click() Text3.Text = Val(Text1.Text) + Val(Text2.Text) End Sub Private Sub Cmdexit_Click() Unload Me End Sub Code for child2 form Private Sub Cmdconvr_Click() Text2.Text = UCase(Text1.Text) End Sub Private Sub Cmdexit_Click() Unload Me End Sub Code for MDI form Private Sub MDIForm_Load() child1.Show child2.Show End Sub Private Sub slch1_Click() child1.Show child2.Visible = False End Sub Private Sub slch2_Click() child2.Show child1.Visible = False End Sub

Compiled By: Er. SRB

Vous aimerez peut-être aussi