dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB5,VB6
Expertise: Intermediate
Aug 22, 2000

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Detect when a new control is added to an ActiveX container

You can easily create ActiveX controls that work as containers for other controls, by setting their ControlContainer property to True. However, VB doesn't offer any event for detecting when the programmer adds or remove controls to the ActiveX control, after placing it on a form's surface.

It's pretty easy to detect such actions with the aid of a Timer control, though. Just place a Timer control on the UserControl's surface, set its Interval property to a suitable value (for example, 500 milliseconds) and then add the following code:


Private Sub Timer1_Timer()
    Static ctrlCount As Integer
    
    If ctrlCount <> ContainedControls.Count Then
        ctrlCount = ContainedControls.Count
        ' a new control has been added or removed
        ' from inside your UserControl
        '
        ' ...add your code here........
        '
    End If
End Sub
If you're working under VB6 you can add the Timer control dynamically, so it's just a matter of copying-and-pasting the following code:

Dim WithEvents tmrNotifier As Timer

Private Sub UserControl_Initialize()
    ' create a new Timer control dynamically
    Set tmrNotifier = Controls.Add("VB.Timer", "tmrNotifier")
    tmrNotifier.Interval = 500
End Sub

Private Sub tmrNotifier_Timer()
    Static ctrlCount As Integer
    
    If ctrlCount <> ContainedControls.Count Then
        ctrlCount = ContainedControls.Count
        ' a new control has been added or removed
        ' from inside your UserControl
        '
        ' ...add your code here........
        '
    End If
End Sub
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date