sas

Topic: Projects using Intrinsic and Professional ActiveX Control


     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.

vb

                                        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

Running the Project:

     Select Start from the Run Menu.   You will find the Common dialog box has become invisible in the run mode window.   The run mode window appears as in the figure 2. On clicking the open button, you will get the open dialog window as in the figure 3.   Click the cancel button in the open dialog window .  Now click the Save button to view the Save window.   Repeat this for viewing all the other windows and see that the project is successful..
vb

                                         Figure 2

vb

                            Figure 3

                      
2. Project using RichTextBox Control:

     The traditional text box control is ideal for text entry at a given font and size.   RichTextBox Control  allows the user to enter text with varying fonts and sizes.   Add the RichTextBox control and the Common Dialog Control to the Toolbox by drawing them from the component dialog box.  Drag a RichTextBox control, Common Dialog Control  and a Command Btton control in the form.   Set the command button caption and name as font.   A font dialog box can be opened only through the Common Dialog control.   The Common Dialog control box will be invisible during run time. .Save the form and the project.    The project at the design time looks as in the figure 4.
vb

                      Figure 4

Entering the Code:

     Open the code window by double clicking the font button.   Enter the codes as shown in the figure 4a and finally save the project.

Private Sub Font_Click()
'Show both printer and screen fonts
CommonDialog1.Flags = cdlCFBoth
CommonDialog1.ShowFont

RichTextBox1.SelFontName = CommonDialog1.FontName

RichTextBox1.SelFontSize = CommonDialog1.FontSize
RichTextBox1.SelBold = CommonDialog1.FontBold
RichTextBox1.SelItalic = CommonDialog1.FontItalic
RichTextBox1.SetFocus
End Sub

        Figure 4a

Running the Project:

     Select Start from the Run menu.   You type any text in the RichTextBox and select it.   Click the font button.   The font dialog box will open.   Set the desired font and size.   On deselecting

the text, you will find the text printed in the desired font and size.   The run mode window is shown in the figure 5.

vb
                        Figure 5

3. Project using DriveListBox, FileListBox, DirListBoc and ImageBox:

     In this project, the DriveListBox, the FileListBox and theDirListBox are coordinated to disk access without any programming.   One can select a gif file from the disk and load  it in the Image box.    The four controls are drawn into the design window and arranged as shown in the figure 6.   In this example we are going todisplayThe ImageBox control  simply appears as empty rectangle in the design mode.   At run time it will be loaded by the a  .gif files.   So change the Pattern property of the FileListBox from its default to *.gif.

 vb

                                              Figure 6

 Entering the Code:

     Open the code window by double clicking the DirListBox.   The codes are entered as shown in the figure 6a.

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub File1_DblClick()
Image1.Picture = LoadPicture(File1.Path & "\" & File1.filename)
End Sub

                           
         Figure 6a     The run mode  window looks as in the figure 7.   The gif file is selected by suitably changing the path list, directory list and finally selecting the required file.

vb
                              Figure 7

  • Tabbed Dialog Control:
     Suppose you want to include a large number of controls in a single form you can divide the form into something like pages using this Tabbed Dialog Control or SS Tab Control.   When you drag the SS Tab Control in the form it presents a container with tabs at the top.   Each tab corresponds to a page of the form.   You can add any number of pages by simply increasing the value of the ‘the TabsPerRow’ property.   Each page can contain a number of components.   The figure 8 shows a form with 4 tabs with some controls placed in tab1.   Similarly you can place controls in other tabs or pages.

vb

                             Figure 8

5. Multiple document Interface:

     The MDI was designed to simplify the exchange of information among documents, all under the same roof.   With a MDI application, you can maintain multiple windows, but not multiple copies of the application.  Data exchange is easier when you can view and compare many documents simultaneously.   The main form or MDI form is not duplicated, but it acts as a container for all the windows, and it is called the parent window.

     A MDI application must have at least two forms, the parent form and one or more child forms.   There can be many child forms, but only one parent form.  He parent form may not contain controls.   While the parent form is open in the design mode, though the icons in the toolbox are not disabled, but you cannot place any control on the form.   But you can place controls in child forms.

To create a MDI application follow these steps:

  • Start a new project, and choose Project>Add MDI form to add the form
  • Set the form’s caption to MDIwindow.
  • Choose Project>Add form to add a regular form.
  • Make this form child by setting its MDIChild property true.   To denote that this is a child form set its caption to MDIChild.
  • Double-click your picture control in the tool box.   It will appear as toolbar to your MDI form.
  • Place three command buttons on this toolbar and change their names and captions to newchild, cascade and tile respectively.
  • The MDI window will look as in the figure 9.  
  • Enter the codes as shown in the figure 9a.
  • Save and run the project.
  • See how you can arrange the child windows in tiles or cascades.  You cannadd any number of child windows by clicking the newchild button.   A typical tile arrangement of child windows is shown in the figure 10 and cascade arrangement of the child windows in the figure 11.

Dim i
Private Sub cascade_Click()
MDIForm1.Arrange 0
End Sub

Private Sub newchild_Click()
Dim obj As Form1
Set obj = New Form1
obj.Caption = obj.Caption & i
obj.Show
i = i + 1
End Sub

Private Sub MDIForm_Load()
i = 2
End Sub

Private Sub tile_Click()
MDIForm1.Arrange 1
End Sub

     Figure 9a

vb

                            Figure 9

vb

                                Figure 10

vb
                                 Figure 11

 

Prev

 

 

 

 

 

 

 

 

 


footer back link


 

Error in my_thread_global_end(): 1 threads didn't exit