+ All Categories
Home > Documents > The Common Dialog Box. Installing the Common Dialog Box May NOT be your standard VB toolbox.

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

Date post: 12-Jan-2016
Category:
Upload: phyllis-maxwell
View: 221 times
Download: 2 times
Share this document with a friend
Popular Tags:
24
The Common Dialog Box
Transcript
Page 1: The Common Dialog Box. Installing the Common Dialog Box May NOT be your standard VB toolbox.

The Common Dialog Box

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

Installing the Common Dialog Box

May NOT be your standard VB toolbox.

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

Step 1:Select Components from the Project Menu

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

Step 2: Check Microsoft CommonDialog Control 6.0

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

The Many Methods of the Dialog Box

Open File .ShowOpen

Save File .ShowSave

Color .ShowColor

Print .ShowPrinter

Help .ShowHelp

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

Common Dialog (Example)

Interface

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

Set the Properties

txtDisplay cmdOpenFile cmdSaveFile cmdFont cmdPrint cmdTextColor cmdBackColor

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

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 labelExit SubFontError:End Sub

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

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.

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

Font Psuedocode

Set Cancel Error flag to 1Error handlerSet Flags property to 1Display the dialog boxSet font properties for bold, italic, font

strike through font size, font name, and properties of text box (example: txtFontBold = CommonDialog1.FontBold)

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

Shortcut Rather than typing txtFontBold = CommonDialog1.FontBoldtxtFontItalic = CommonDialog1.FontItalicEtc.Use the shortcutWith txtDisplay.Font

.Bold = CommonDialog1.FontBold

.Italic = CommonDialog1.FontItalicetc.

End With

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

Font CodeCommonDialog1.CancelError = FalseOn Error GoTo FontErrorWith CommonDialog1

.FontName = txtWord.FontName

.Flags = 1

.ShowFonttxtWord.Font.Name = .FontNametxtWord.FontBold = .FontBoldtxtWord.FontItalic = .FontItalictxtWord.FontSize = .FontSize

End WithExit SubFontError:

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

The Color Dialog

set CancelError to trueError handlerdisplay the color dialog boxset the text box property (eitherBackColor or ForeColor) to CommonDialog1.ColorError routine: no code needed.

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

How Files Work

Buffer Disk Drive

Computer

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

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*"

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

The Open Dialog:Getting the File Name

With CommonDialog1set the filterset the Filter index = 1display Open common dialogset FileName to .FileName

End With

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

The Open Dialog:Reading the File

Declare integer for bufferAssign bufferOpen the file (FileName) For

InputRead in the whole file

Input(LOF(F), F to the text boxClose the file

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

Open Dialog: CodeOn Error GoTo OpenErrorDim F As IntegerF = FreeFileCommonDialog1.CancelError = TrueCommonDialog1.Filter = "Text Files (*.txt)|

*.txt| Web Files (*.htm)|*.htm" CommonDialog1.ShowOpenOpen CommonDialog1.FileName For Input As FtxtWord.Text = Input(LOF(F), F)Close #F

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

Saving A FileSet Cancel ErrorError HandlerDim F for buffer numberset the filterset the filter index to 1show the save boxset file name to dialog box file nameOpen the file for outputPrint #F, txtWord.TextClose the fileF

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

The Print Dialog

CommonDialog1.ShowPrinter Some of the properties returned are:

FromPage ToPageToPage Copies

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

To Print

Use the object's Print method

Printer.Print <what you want printed>

Printer.EndDoc To print the contents oftext boxPrinter.Print txtWord.TextPrinter.EndDoc

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

Save or Save As?

If (the file has a name)save using the filename

elseshow the Save dialog

End If

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

You must:

Form_Load - Set FileName to "“mnuSaveAs - Set FileName to CommonDialog1.FileName mnuOpen - Set FileName to CommonDialog1.FileName mnuNew - Set FileName to ""

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

And in conclusion…

You should now be able to add save, save as, open, print, and set font to your word processor!


Recommended