Part I - Create and Implement the cControl_WebTabControl Class

Create the Composite Control class from the template, replace placeholder values, and implement the class in the object model.

Contents

Step 1 - Create the basic class

Step 2 - Add properties and procedures


Step 1- Create the basic class

  1. Right-click in the Project Explorer pane of the VBA Editor Window and select Insert -> Class Module.
  2. Rename the new class module to cControl_WebTabControl.
  3. Open the class module, cControl_TEMPLATE.
  4. Select All text CTRL+A, and copy CTRL+C.
  5. Open the class module, cControl_WebTabControl.
  6. Select All text, and paste CTRL+V,

Make the following code changes:

1. In the following line in the declarations section, highlight SourceCtrlType_ and press CTRL+H:
Private WithEvents o As SourceCtrlType_ 'must replace with an event-capable object
2. In the dialog box, in the Replace All dropdown, type TabControl and select Replace All. Two replacements will be made.
3. With the Replace dialog still open, type ControlType_ in the Find What dropdown, and cControl_WebTabControl in the Replace With dropdown. Replace all occurences. Two replacements will be made. Close the Replace dialog
4. Then, change the following code in the Initialize() procedure:
    With asGeneric(m_oRef)
            
        If .ControlType = ccControl_Generic Then
            
            Set o = .Control                 'Control, Form, Report, Section
            Set .ParentEventHandler = Me
            
        Else
            
            Set o = ctl
                
        End If
        
    End With


Change the line
Set o = .GenericCtrlType_ 'Control, Form, Report, Section
to read:
Set o = .Control 'Control, Form, Report, Section

Then delete the If...Then...Else...End If logic, as well as the code in the "Else" section.

The entire section should now consist of only two lines:

            Set o = .Control                 'Control, Form, Report, Section
            Set .ParentEventHandler = Me



NOTE: This section of the Initialize() procedure manages the assignment of the primary control reference for our cControl class. If the control reference is an ActiveX control, or some other type of object, the control reference will be passed wrapped in a cControl_Generic object and we have to retrieve the reference using a specific property (Control, Form, Section, Report, etc.). If, however, the control reference is a Composite Controls object (or implements the iControl interface), then we can simply pass the control itself as the reference. This is what the logic surrounding the above line of code manages. You may delete this logic and replace it with one of two lines of code since an implemented cControl class will likely never take references to both types of objects.


Finally, in the Support_Globals module, under the cControlType enumerator, add the following line to the section marked "Composite Controls", add the following line of code:
ccControl_WebTabControl = 1500

In the Support_CompositeControlManager module, in the GetHandler() procedure, add the following code in the Select...Case...End Select logic:

    Case ccControl_WebTabControl
    
        Set GetHandler = New cControl_WebTabControl


Be sure to save your changes.


Top


Step 2 - Add properties and procedures

In this step we need to add the extra code to our WebTabControl class which will manage the interaction between the ActiveX TabControl and the cControl_WebButton objects we'll be using as tabs. There is only one point where the WebButton object must inreact with the TabControl object, and that is when the WebButton "tab" will be clicked (or selected), thus triggering the corresponding Page in the TabControl to be made visible. This requires adding one property (the PageTabs collection) and one procedure (the ShowPage() callback function).

Add the PageTabs Collection

Find the following line in the declarations section:
Private m_colChildren As Collection
Change the declaration from Private to Public and use CTRL+H to replace all occurrences of m_colChildren to PageTabs. Two replacements will be made (the other occurrence is in the Terminate() procedure).
When you're done, the above line should read:
Public PageTabs As Collection

Add the ShowPage() callback and modify the delegator

Find the iCallback_Delegator() function in the class module. Insert the ShowPage() function before it:
Public Sub ShowPage(handler As cControl_WebButton)

    Dim PageIndex As Integer
    
    PageIndex = handler.CommandButton.Tag
    
    If PageIndex <> o.Value Then
    
        o.Value = PageIndex
        
    End If

End Sub

The above code simply takes a reference to the cControl_WebButton object which was clicked and uses it to determine which page needs to be displayed. Note that the page index of the page to be displayed is stored in the Tag property of the cControl_WebButton's command button control.

Finally, add the following line of code to the Select Case logic in the iCallback_Delegator() subroutine:
    Case "ShowPage"
    
        ShowPage handler


Top

Now move on to the next part, Implement the Support_WebTabControl Module

Last edited Feb 26, 2011 at 7:59 AM by vba_junkie, version 10

Comments

No comments yet.