Windows Common Dialogs

Using the Common Dialog Control

In this exercise, you will add the Common Dialog component to a Visual Basic application. The Common Dialog control provides users with a standard Windows dialog to change font, save, open , and print files.

* To use the Common Dialog control in Visual Basic

  1. Start Visual Basic.
  2. Select Standard EXE .
  3. Insert two command buttons on Form1 .
  4. Set the following properties:
    Control Property Value
    Command1 Name CmdSave
      Caption &Save
    Command2 Name CmdExit
      Caption E&xit

  5. Right-click on the Toolbox . Select Components from the pop-up menu, and select the Microsoft Common Dialog Control .
  6. Insert a Common Dialog control on Form1 .
  7. Repeat Step 5 and select Microsoft Rich Textbox Control 5.0 .
  8. Change the name of RichTextBox1 to rtbNote .
  9. In the click event of cmdSave , enter the following code:
     Private Sub cmdSave_Click() Dim FileName As String On Error GoTo ErrorHandler CommonDialog1.Filter = "Document (*.doc)*.doc" CommonDialog1.ShowSave rtbNote.SaveFile CommonDialog1.FileName Exit Sub ErrorHandler: MsgBox Err.Description, , "Error" End Sub 
  10. In the click event of cmdExit , enter the following code:
     Unload Me 
  11. Run the application.
  12. Type some text in the Rich Textbox and click Save .
  13. The Common Dialog control will appear and allow you enter the name of the file to be saved. Save the file as Exercise1.doc in the WA\Practice\Ch12 folder.
  14. Click Exit .

Lesson Summary

You can access a number of standard controls and dialogs through ActiveX controls. When developing an application, you can use these controls and dialogs to give your forms a standard look and feel. General purpose controls include components such as the Slider, ProgressBar, and Tab. Organizational controls include components such as the Toolbar and the Status Bar. List View and Tree are examples of list controls. Text controls include components such as UpDown and the Rich Text Box. The Handwriting, Boxed Edit, and Ink Edit components are Pen controls.

In Windows 95 and Windows NT, the Common Dialog Control provides standard dialogs such as Open , Save , and Find .



Microsoft Windows Architecture Training
Microsoft Windows Architecture for Developers Training Kit
ISBN: B00007FY9D
EAN: N/A
Year: 1998
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net