ActiveX Objects and Controls - Visual Basic 6.0

Table of Contents [Hide/Show]


   Basics
      Project Properties
      Procedure Attributes
   ActiveX Controls
      Life Cycle
      Control Properties
      Extender Object
      Ambient Object
      Property Persistence
         Method
         Code Sample
      Standard Events
      Custom Events
      Property Pages

{outline||<1> - |

.<1> - }

Basics

Project Properties

Item Description
Project Name the project as seen in both the Object Browser and code
Help File Name  
Project Help Context ID  
Project Description the description as it appears in the Project References dialog, so it should be a user-friendly description.
Application Title (Make tab) the title as it appears in the Task Manager

Procedure Attributes

Item Description
Description as it appears in the Object Browser
Help Context ID the help context ID for this procedure. (See project properties, above, to specify the help file)
Procedure ID
  • (Default) = the default property if none is specified
  • Caption = property will update dynamically on the form as the user types
  • –4 = enumeration property

  • ActiveX Controls

    Life Cycle

    State Notes
    Control Design-time no control events are triggered
    Host Design-time; Control Run-time closing the object design window for the ActiveX control enables its button on the VB Toolbox, and initializes the ActiveX control object. Opening the object design window again disables the VB Toolbox button, and terminates the ActiveX control object.
    Host Run-time; Control Run-Time  

    Control Properties

    Property Description
    Project Name the name of the type library for the compiled OCX file
    Project Description the text the users will see when displaying a list of all installed ActiveX components
    Name becomes the class name for the control

    Extender Object

    Apparent built-in properties such as Name, Top, Left, and Visible are provided by the Extender object. Not all host apps extend the same properties with their Extender objects, and some apps don’t support the Extender object at all (e.g., Access 97 and Internet Explorer 3.0). Use the Extender object only with error-handling!

    Ambient Object

    The Ambient object corresponds to the form hosting your UserControl. It is used to determine properties of the host form so that those properties can be assimilated by the control.

    Property Persistence

    Method

    Use the PropertyChanged "property-name" statement to tell the Properties window to update its display, and to tell VB that the form’s property storage has changed. Note: In an ActiveX Document, use the PropertyChanged routine without an argument


    Code Sample

    Property Let Active(x as Boolean)
       timMain.Enabled = x
       PropertyChanged "Active"
    End Property
    
    Private UserControl_WriteProperties(PropBag as PropertyBag)
      ' Repeat the following line for each property
      PropBag.WriteProperty "Active", timMain.Enabled, True
    End Sub
    
    Private UserControl_ReadProperties(PropBag as PropertyBag)
      ' Repeat the following line for each property
      Active = PropBag.ReadProperty("Active", True)
    End Sub

    Standard Events

    Event Occurs Purpose
    Resize As the control is resized, including when it is first placed on a form at Host Design Time Allow code to resize constituent controls
    InitProperties Only once: when the control is instantiated at Host Design-Time Initializes properties when you insert an instance of the control onto a form at Host Design-Time only
    AmbientChanged When certain properties of the host form change To allow the UserControl to assimilate properties of the host form
    WriteProperties Just before VB destroys the instance of the running control at Host Design-Time To retrieve changes to the ActiveX control and persist them into the form’s storage
    ReadProperties Just before VB instantiates the control at Host Design Time To retrieve property settings for the ActiveX control from the form’s storage and apply them to the control

    Custom Events


    Event event-name([argument-list])


    RaiseEvent event-name([argument-list])

    Property Pages



    Portions of this article were taken from AppDev Advanced Visual Basic 5.0, Chapter 33