I made a new UserControl and it's ControlContainer property is set to True, inside the control there is a picture box.
how can i make each control that is drawn inside my control to be the child of the picture?
anyone?
Printable View
I made a new UserControl and it's ControlContainer property is set to True, inside the control there is a picture box.
how can i make each control that is drawn inside my control to be the child of the picture?
anyone?
VB Code:
Dim c As Control For Each c In Controls If Not c Is MyPicturebox Then Set c.Container = MyPicturebox End If Next
That should do it.
now how do I know when the user put a control inside my UserControl?
Just out of curiosity, what about using the SetParent API?
Would that do the same thing in a usercontrol?
Just need to draw the control @ design time & Perfect!
VB Code:
[color="#0000A0"]Private[/color] [color="#0000A0"]Declare[/color] [color="#0000A0"]Function[/color] SetParent [color="#0000A0"]Lib[/color] "user32" ([color="#0000A0"]ByVal[/color] hWndChild [color="#0000A0"]As[/color] [color="#0000A0"]Long[/color], [color="#0000A0"]ByVal[/color] hWndNewParent [color="#0000A0"]As[/color] [color="#0000A0"]Long[/color]) [color="#0000A0"]As[/color] [color="#0000A0"]Long[/color] [color="#0000A0"]For[/color] I = UserControl.ContainedControls.Count [color="#0000A0"]To[/color] 1 Step -1 SetParent UserControl.ContainedControls.Item(I - 1).hWnd, warea.hWnd [color="#0000A0"]Next[/color] I
Thanks RobDog888 :thumb:
Change the code to :
VB Code:
[color="#0000A0"]Private[/color] [color="#0000A0"]Sub[/color] UserControl_Show() [color="#0000A0"]If[/color] UserControl.Ambient.UserMode = [color="#0000A0"]True[/color] [color="#0000A0"]Then[/color] [color="#00A000"]' so vb wont crash[/color] [color="#0000A0"]For[/color] I = UserControl.ContainedControls.Count [color="#0000A0"]To[/color] 1 Step -1 [color="#0000A0"]If[/color] GetParent(UserControl.ContainedControls.Item(I - 1).hWnd) <> warea.hWnd [color="#0000A0"]Then[/color] SetParent UserControl.ContainedControls.Item(I - 1).hWnd, warea.hWnd UserControl.ContainedControls.Item(I - 1).Left = warea.ScaleWidth - UserControl.ContainedControls.Item(I - 1).Width [color="#0000A0"]End[/color] [color="#0000A0"]If[/color] [color="#0000A0"]Next[/color] I [color="#0000A0"]End[/color] [color="#0000A0"]If[/color] [color="#0000A0"]End[/color] [color="#0000A0"]Sub[/color]
No prob. Trojan.