VLFormDesigner Reference

EventCreateControl

See Also See Also Applies To Applies To

This event occurs before LoadControlData, during LoadLayout operation. It provides an opportunity to the programmer to perform the control loading instead of letting the form designer do it.

This event should be used to load controls in a control array. (see Remark )

 

Syntax

Private Sub object_CreateControl (ByVal sType As String, ByVal sName As String, ByVal ContainerCtrl As Object, ByVal nIndex As Long, ByRef aNewControl As Object)

 

The CreateControl event syntax has these parts:

Part Description
object An object expression that evaluates to VLFormDesigner.
sType An string specifying the ProgID of the control being added.
sName An string specifying the name to be used for the control being added.
ContainerCtrl Specifies the container control to which new control should be added.
nIndex Specifies the index value to be used for the control. If the control is not expected to be a part of control array, then value of this parameter will be -1.
aNewControl Return the reference of the newly added control through this parameter.

 

Remark

This event is used to provide support for use of control arrays with VLFormDesigner.

VLFormDesigner cannot add new members to a control array. If you need to use control arrays, then you will have to load controls on behalf of VLFormDesigner during this event. Following piece of code demonstrates the use of this event :

'------------------------------------------------------
' The sample assumes that a Label control array with 
' name Label1 already exists on the form
'------------------------------------------------------
Private Sub VLFormD1_CreateControl(ByVal sType As String, ByVal sName As String, _
ByVal ContainerCtrl As Object, ByVal nIndex As Long , aNewControl As Object)
   If Not (nIndex = -1)  Then
      Select Case  sType
         Case "VB.Label"
            If (sName = "Label1") Then
               'zero'th member is already loaded
               If Not (nIndex = 0)  Then
                  Load Label1(nIndex)
End If
               Set aNewControl = Label1(nIndex)
            End If
      End Select
   End If
End Sub