Common Dialog Boxes - VB6.0

 

VISUAL BASIC 6.0

 

COMMON DIALOG BOXES

In VB6.0, to use a set of predefined standard dialog boxes, which are

        File Opening and Saving

        Font and Color selection

        Printing and Previewing

To use the Common Dialog Control, you first place this control on form.

The Common Dialog Control may not appear in your toolbox. 

It is a custom control and you must add it to VB before you can use it. 

Custom controls are stored in files with an extension of .ocx in Windows/System folder. 

Open the Project menu and choose Components; see Microsoft Common Dialog Control 6.0 in the list. 

Make sure that a check appears next to the item and its tool should appear in your toolbox.


Using a Common Dialog Box

After place a Common Dialog Control on form, to display any of its dialog boxes at run time. 

General Form

Object.ShowMethod

The method can be one of the following

Dialog Box

Method

Open

ShowOpen

Save As

ShowSave

Color

ShowColor

Font

ShowFont

Print

ShowPrint

Color Dialog Box

The color selected by the user is stored in the Color Property.

To assign this property to another object such as a control (label, text, etc.,) or the form.

Example

Private Sub MNUCOLOR_Click()

MsgBox "Now, select Background color of the form"

CommonDialog1.ShowColor

Form1.BackColor = CommonDialog1.Color

MsgBox "Now, select Forecolor of the label"

CommonDialog1.ShowColor

Label1.ForeColor = CommonDialog1.Color

End Sub



Font Dialog Box

The font properties for the common dialog control are different from those used for other controls.  Instead of a group of properties for a Font object, each Font property is listed separately.

Font Object of

Other Controls

Font Property of

Common Dialog Box

Values

Font.Bold

FontBold

True or False

Font.Italic

FontItalic

True or False

Font.Name

FontName

System dependent

Font.Size

FontSize

Font dependent

Font.StrikeThrough

FontStrikeThru

True or False

Font.Underline

FontUnderline

True or False

Example

Private Sub MNUFONT_Click()

MsgBox "Now, Select Font of the label"

CommonDialog1.ShowFont

With Label1.Font

        .Name = CommonDialog1.FontName

        .Bold  = CommonDialog1.FontBold

        .Italic = CommonDialog1.FontItalic

End With

End Sub



Comments

Popular posts from this blog

Backtracking - N-Queens Problem, Sum of Subsets, Graph Colouring, Hamiltonian Cycle

Divide and Conquer Technique - Binary Search, Quick Sort, Merge Sort

GRAPH THEORY