1 / 24

The Common Dialog Box

The Common Dialog Box. Installing the Common Dialog Box. May NOT be your standard VB toolbox. Step 1: Select Components from the Project Menu. Step 2: Check Microsoft CommonDialog Control 6.0. Open File. .ShowOpen. Save File. .ShowSave. Color. .ShowColor. Print. .ShowPrinter. Help.

sera
Download Presentation

The Common Dialog Box

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Common Dialog Box

  2. Installing the Common Dialog Box May NOT be your standard VB toolbox.

  3. Step 1:Select Components from the Project Menu

  4. Step 2: Check Microsoft CommonDialog Control 6.0

  5. Open File .ShowOpen Save File .ShowSave Color .ShowColor Print .ShowPrinter Help .ShowHelp The Many Methods of the Dialog Box

  6. Common Dialog (Example) Interface

  7. Set the Properties • txtDisplay • cmdOpenFile • cmdSaveFile • cmdFont • cmdPrint • cmdTextColor • cmdBackColor

  8. Write the Code: Error Checking CommonDialog1.CancelError = False On Error GoTo FontError ‘where to go …The code goes here … and here FontError: ‘this is a label Exit Sub FontError: End Sub

  9. The Font Dialog: Flags • The of the Common Dialog box uses other flags to control behaviors. • The Font dialog Flags property must be set to the value 1 to load the system fonts. • After the font dialog box appears and selections are made, the values the user selected are available to the program.

  10. Font Psuedocode Set Cancel Error flag to 1 Error handler Set Flags property to 1 Display the dialog box Set font properties for bold, italic, font strike through font size, font name, and properties of text box (example: txtFontBold = CommonDialog1.FontBold)

  11. Shortcut Rather than typing txtFontBold = CommonDialog1.FontBold txtFontItalic = CommonDialog1.FontItalic Etc. Use the shortcut With txtDisplay.Font .Bold = CommonDialog1.FontBold.Italic = CommonDialog1.FontItalicetc. End With

  12. Font Code CommonDialog1.CancelError = False On Error GoTo FontError With CommonDialog1 .FontName = txtWord.FontName.Flags = 1.ShowFonttxtWord.Font.Name = .FontNametxtWord.FontBold = .FontBoldtxtWord.FontItalic = .FontItalictxtWord.FontSize = .FontSize End With Exit Sub FontError:

  13. The Color Dialog • set CancelError to true • Error handler • display the color dialog box • set the text box property (either • BackColor or ForeColor) to CommonDialog1.Color • Error routine: no code needed.

  14. Disk Drive Buffer How Files Work Computer

  15. The Open File Dialog • Filter begins and ends with a quote marks. The pipe | is used as a separator. "Text Files (*.txt) | *.txt| All Files (*.*) |*.*|HTML Files (*.htm)|*.htm*"

  16. The Open Dialog:Getting the File Name With CommonDialog1 set the filterset the Filter index = 1display Open common dialogset FileName to .FileName End With

  17. The Open Dialog:Reading the File Declare integer for buffer Assign buffer Open the file (FileName) For Input Read in the whole file Input(LOF(F), F to the text box Close the file

  18. Open Dialog: Code On Error GoTo OpenError Dim F As Integer F = FreeFile CommonDialog1.CancelError = True CommonDialog1.Filter = "Text Files (*.txt)|*.txt| Web Files (*.htm)|*.htm" CommonDialog1.ShowOpen Open CommonDialog1.FileName For Input As F txtWord.Text = Input(LOF(F), F) Close #F

  19. Saving A File Set Cancel Error Error Handler Dim F for buffer number set the filter set the filter index to 1 show the save box set file name to dialog box file name Open the file for output Print #F, txtWord.Text Close the fileF

  20. The Print Dialog CommonDialog1.ShowPrinter Some of the properties returned are: • FromPage • ToPage • ToPage • Copies

  21. To Print Use the object's Print method Printer.Print <what you want printed> Printer.EndDoc To print the contents oftext box Printer.Print txtWord.Text Printer.EndDoc

  22. Save or Save As? If (the file has a name) save using the filename else show the Save dialog End If

  23. You must: • Form_Load - Set FileName to "“ • mnuSaveAs - Set FileName to CommonDialog1.FileName • mnuOpen - Set FileName to CommonDialog1.FileName • mnuNew - Set FileName to ""

  24. And in conclusion… You should now be able to add save, save as, open, print, and set font to your word processor!

More Related