Page 218 - Open Soource Technologies 304.indd
P. 218
Event Driven Programming
9.6.1 To Display a Form as a Modal Dialog Box
• Use the Show method with a style argument of vbModal (a constant for the value 1).
‘ Display frmAbout as a modal dialog.
frmAbout.Show vbModal
9.6.2 To Display a Form as a Modeless Dialog Box
• Use the Show method without a style argument.
‘ Display frmAbout as a modeless dialog.
frmAbout.Show
If a form is displayed as modal, the code following the Show method is not
executed until the dialog box is closed. However, when a form is shown as
modeless, the code following the Show method is executed immediately after
the form is displayed.
The Show method has another optional argument, owner, that can be used to specify a parent-
child relationship for a form. we can pass the name of a form to this argument to make that form
the owner of the new form.
9.6.3 To Display a Form as a Child of Another Form
• Use the Show method with both style and owner arguments.
‘ Display frmAbout as a modeless child of frmMain.
frmAbout.Show vbModeless, frmMain
Using the owner argument with the Show method ensures that the dialog box will be minimized
when it’s parent is minimized, or unloaded should the parent form be closed.
9.7 Predefined Dialog Boxes
The easiest way to add a dialog box to your application is to use a predefined dialog, because
you don’t have to worry about designing, loading, or showing the dialog box. However, your
control over its appearance is limited. Predefined dialog boxes are always modal. The following
table lists the functions you can use to add predefined dialog boxes to your Visual Basic
application.
Table 9.3: Functions to Add Predefined Dialog
Use this function To do this
InputBox function Display a command prompt in a dialog box, and return
whatever is entered by the user.
MsgBox function Display a message in a dialog box, and return a value
indicating the command button was clicked by the user.
212 LOVELY PROFESSIONAL UNIVERSITY