SetParent and UserControls in VB6
Posted on 2002-05-30
I have a user control on a form. The only control on the usercontrol is a second usercontrol.
At run time, I want to run various initialization code in the first control to set up the second one and then set the parent of the second on to be the form rather than the first user control so that I can drag it around the entire form with out being limited to the boundaries of the first control, which would now be made invisible.
If I can get this to work, I can make a nice, tidy encapsulated module.
What happens when I use the setparent api using the hwnd of the second (inner) control and the hwnd of the form is the second control moves to the top of the first control but is still contained by it.
I added a second form in an attempt to see what was happending. Assigning the hwnd of the inner control to the second form MOVED BOTH CONTROLS to the second form.
Then I tried adding a form inside of the usercontrol project and placed the inner control on it. Now when I try to set the parent of the innercontrol, the entire form it is on comes with it.
Either of the above techniques work if I try to move a textbox. It appears to be a "problem" specific to a UserControl.
I know this is a confusing description of the problem. Any help is appreciated.
In case anyone asks, I'm getting the usercontrols hwnd by adding a public property to the user control which returns UserControl.ContainerhWnd.