HOW TO: Call the Save Method of an MDI Child Form from the MDI Form Toolbar Menu by Using Visual Basic 6.0 (818367)
The information in this article applies to:
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
SUMMARYThis step-by-step article describes how to call the Save method in a multiple document interface (MDI) child form when you
click the Toolbar button on the MDI Form. back to the topRequirementsThe following lists the recommended hardware, software, network
infrastructure, and service packs that you must have: Microsoft Visual
Basic 6.0 This article assumes that you are familiar with the
following:
- Microsoft Visual Basic 6.0 IDE
- Microsoft Visual Basic 6.0 programming
back to the
topCall the Save Method in an MDI Child Form- Start Visual Basic 6.0.
- On the File menu, click New
Project. In the New Project dialog box, click
Standard EXE, and then click OK.
- In Solution Explorer, right-click Form1,
and then click Remove Form1.
- On the Project menu, click Add MDI
Form.
- In the Add MDI Form dialog box, click
MDI Form, and then click Open.
- Set the Name property of the MDI
Form to frmMDI, and then set the
WindowState property to Maximized.
- On the Project menu, click Add
Form. In the Add Form dialog box, click
Form, and then click Open.
By default, the Form1 form is created - Set
the MDIChild property of the Form1 form to
True, and then set the Borderstyle property
of the Form1 form to Fixed Dialog.
- Add a command button and a text box to the Form. Set the
Name property of Command Button to
cmdSave, and then set the Caption
property to Save.
- To view the code editor, double-click the
Save command button. Change the Click event scope of the cmdSave event handler from Private to
Public.
- Repeat step 5 through step 8 two times. This adds MDI child
form Form2 and MDI child form
Form3.
- Add the following code to the Click event of the Save command button of the MDI
child form Form1:
MsgBox " Save event of MDI Child Form: Child1" - Add the following code to the Click event of the Save command button of the MDI
child form Form2:
MsgBox " Save event of MDI Child Form: Child2" - Add the following code to the Click event of the Save command button of the MDI
child form Form3:
MsgBox " Save event of MDI Child Form: Child3" - On the Project menu, click
Components. Click Microsoft Windows Common Controls
6.0, and then click OK.
- Double-click the Toolbar control in the
toolbox. Right-click Toolbar, and then click
Properties.
- Click the Buttons tab in the
Toolbar Properties dialog box, and then click Insert
Button to add a Toolbar button. Set the Caption
property of the Toolbar button to Save, and then set the
Key property to Save.
- Click OK.
- To view the code editor, double-click the
Toolbar to open in Code view.
- Add the following code to the Click event of the Toolbar:
On Error GoTo NoActiveForm
Select Case Button.Key
Case "save"
Me.ActiveForm.cmdSave_Click
End Select
Exit Sub
NoActiveForm:
MsgBox Err.Description
- Add the following code to the Load event of the MDI Form frmMDI to show
all the MDI child forms when the application starts.
Form1.Show
Form2.Show
Form3.Show
- On the Project menu, click
Project Properties. In the Startup Object
combo box on the General tab, click frmMDI as
the startup object.
back to the
topVerify That It Works- On the Run menu, click
Start.
The MDI application with three MDI child
forms appears. Each MDI child form has a text box and a Save
command button. - Click Save on the Toolbar while the Form
Child3 is active. A message box displays the following
message:
Save event of MDI child form:
Child3 - Randomly make other MDI child forms active, and then click
Save on the toolbar to see if the correct child form Save method is called whenever you click Save on the
toolbar.
back to the
top
Modification Type: | Minor | Last Reviewed: | 8/19/2005 |
---|
Keywords: | kbui kbControl kbMDI kbToolbar kbHOWTOmaster KB818367 kbAudDeveloper |
---|
|