Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Detect when a new control is added to an ActiveX container

Total Hit ( 2652)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


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:

Click here to copy the following block
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:

Click here to copy the following block
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


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.