VISUAL BASIC_6
 

3. Projects using Intrinsic and Professional ActiveX Control(2)


In this Lesson we will explain some  five Projects as shown below using ActiveX Controls.

 ·        Common Dialog Control

·        RichTextBox Control

·        DriveListBox, FileListBox, DirListBox and PictureBox Controls

·        SS Tab Control

·        MDI Form

1. Project using the Common Dialog Control:

The Common Dialog Control is first drawn into the Toolbox from Component Dialog Menu.   This dialog box gives support to use  some of the dialog boxes supplied by  Windows 95 in your own projects.   In the absence of this control you have to write codes for creating such dialog boxes,.   The dialog boxes supported by Common Dialog Control  are Open, Save, Print, PrintSetup, Font, Color and Help.   Drag a Common  Dialog Control, and seven command buttons in the form.    Give the name and caption property of the Command buttons as shown in the figure 1.


                                         Figure 1

 Entering codes for the Command Buttons:

Open the code window by double clicking the command button and write the code as shown in the figure 1a.

Private Sub Color_Click()

    ' Show the dialog with an initial color and show the full dialog

    ' To use two flag parameters, simply add them together

    CommonDialog1.Flags = cdCClFullOpen + cdlCCRGBInit

    ' Set currently selected color to blue

    CommonDialog1.Color = RGB(0, 0, 255)

    CommonDialog1.ShowColor

    ' Place color selected by user in variable

    returnedColor = CommonDialog1.Color

End Sub

 

Private Sub Font_Click()

    ' Set flags to show both printer and screen fonts

    ' Alternately, use the flag cdlCFPrinterFonts or cdlCFScreenFonts to show a specific set

    CommonDialog1.Flags = cdlCFBoth

    CommonDialog1.ShowFont

    ' Display selected font

    MsgBox "Font Name: " & CommonDialog1.FontName & " Font Size: " & CommonDialog1.FontSize, vbInformation, "Selected Font"

End Sub

 

Private Sub Help_Click()

    ' Show the VB help file

    CommonDialog1.HelpFile = "VB.HLP"

    ' Display the contents of the file

    CommonDialog1.HelpCommand = cdlHelpContents

    CommonDialog1.ShowHelp

End Sub

 

Private Sub Open_Click()

    ' Clear current filename

    CommonDialog1.filename = ""

    ' Show only text files to open

    CommonDialog1.Filter = "Text Files|*.txt|All Files|*.*"

    CommonDialog1.ShowOpen

    ' Check to make sure user selected a file

    If CommonDialog1.filename <> "" Then

        MsgBox "File: " & CommonDialog1.filename, vbInformation, "Selected file"

    End If

End Sub

 

Private Sub Print_Click()

    ' Clear current flags

    CommonDialog1.Flags = 0

    CommonDialog1.ShowPrinter

End Sub

 

Private Sub PrintSetup_Click()

    ' Show print setup dialog

    CommonDialog1.Flags = cdlPDPrintSetup

    CommonDialog1.ShowPrinter

End Sub

 

Private Sub Save_Click()

    ' Set default save filename

    CommonDialog1.filename = "Doc1.txt"

    ' Save as text file

    CommonDialog1.Filter = "Text Files|*.txt"

    CommonDialog1.ShowSave

End Sub

Figure 1a


 

Copyright © 2001 Selfonline-Education. All rights reserved.