Microsoft KB Archive/174553

= How To Detect When a Control Is Placed into a UserControl =

Article ID: 174553

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q174553



SUMMARY
This article illustrates how you can create an ActiveX control that detects when a control is placed on it at design time.



Step-by-Step Example
The following example creates a custom ActiveX control that can perform some action when another control is placed on top of it:

 Start a new ActiveX Control project. UserControl1 is added by default. Set the ControlContainer property to True.  Add a Timer control to UserControl1. Add the following code to the Timer event of Timer1: Private Sub Timer1_Timer Dim UserCtrl As Object Debug.Print UserControl.ContainedControls.Count For Each UserCtrl In UserControl.ContainedControls Debug.Print UserCtrl.Name Next

End Sub  Set the Timer1 Interval property to 1000 so Private Sub Timer1_Timer gets called every 1 second. Close the UserControl1 design window. Click Add Project on the File menu. Select "Standard EXE" and click Open.

NOTE: You now have a project group consisting of an ActiveX control project and a Standard EXE project. Click Immediate Window on the View menu.</li> Draw the UserControl1 (the control you just created in your group) on Form1.</li> Select any other control from the toolbox and put it on top of UserControl1.</li></ol>

RESULTS: When you draw another control on top of UserControl1, the count of how many controls you have added plus the name of each control appears in the Immediate Window.

Additional query words: Active kbActiveX kbVBp500 kbVBp600 kbdsi kbDSupport kbVBp kbInternet

Keywords: kbhowto KB174553

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.