Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "The Common Dialog Box. Installing the Common Dialog Box May NOT be your standard VB toolbox."— 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 The Many Methods of the Dialog Box Open File.ShowOpen Save File.ShowSave Color.ShowColor Print.ShowPrinter Help.ShowHelp

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.FontItalic etc. End With

12 Font Code CommonDialog1.CancelError = False On Error GoTo FontError With CommonDialog1.FontName = txtWord.FontName.Flags = 1.ShowFont txtWord.Font.Name =.FontName txtWord.FontBold =.FontBold txtWord.FontItalic =.FontItalic txtWord.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 How Files Work Buffer Disk Drive 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 filter set the Filter index = 1 display Open common dialog set 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 Copies

21 To Print Use the object's Print method Printer.Print 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!


Download ppt "The Common Dialog Box. Installing the Common Dialog Box May NOT be your standard VB toolbox."

Similar presentations


Ads by Google