Results 1 to 7 of 7

Thread: changing the owner of a control [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member Trojan's Avatar
    Join Date
    Dec 2003
    Location
    Area 51
    Posts
    280

    Resolved changing the owner of a control [RESOLVED]

    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?
    Last edited by Trojan; Sep 25th, 2004 at 05:06 PM.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    VB Code:
    1. Dim c As Control
    2.  
    3. For Each c In Controls
    4.     If Not c Is MyPicturebox Then
    5.         Set c.Container = MyPicturebox
    6.     End If
    7. Next

    That should do it.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Hyperactive Member Trojan's Avatar
    Join Date
    Dec 2003
    Location
    Area 51
    Posts
    280

    ok...

    now how do I know when the user put a control inside my UserControl?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Just out of curiosity, what about using the SetParent API?
    Would that do the same thing in a usercontrol?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Hyperactive Member Trojan's Avatar
    Join Date
    Dec 2003
    Location
    Area 51
    Posts
    280

    Cool RobDog888 you Da MAN !!!

    Just need to draw the control @ design time & Perfect!

    VB Code:
    1. [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]
    2.  
    3. [color="#0000A0"]For[/color] I = UserControl.ContainedControls.Count [color="#0000A0"]To[/color] 1 Step -1
    4.   SetParent UserControl.ContainedControls.Item(I - 1).hWnd, warea.hWnd
    5.  [color="#0000A0"]Next[/color] I

    Thanks RobDog888

  6. #6

    Thread Starter
    Hyperactive Member Trojan's Avatar
    Join Date
    Dec 2003
    Location
    Area 51
    Posts
    280

    Talking Oh... found a bug and fixed it!

    Change the code to :

    VB Code:
    1. [color="#0000A0"]Private[/color] [color="#0000A0"]Sub[/color] UserControl_Show()
    2.  [color="#0000A0"]If[/color] UserControl.Ambient.UserMode = [color="#0000A0"]True[/color] [color="#0000A0"]Then[/color] [color="#00A000"]' so vb wont crash[/color]
    3.  [color="#0000A0"]For[/color] I = UserControl.ContainedControls.Count [color="#0000A0"]To[/color] 1 Step -1
    4.   [color="#0000A0"]If[/color] GetParent(UserControl.ContainedControls.Item(I - 1).hWnd) <> warea.hWnd [color="#0000A0"]Then[/color]
    5.    SetParent UserControl.ContainedControls.Item(I - 1).hWnd, warea.hWnd
    6.    UserControl.ContainedControls.Item(I - 1).Left = warea.ScaleWidth - UserControl.ContainedControls.Item(I - 1).Width
    7.   [color="#0000A0"]End[/color] [color="#0000A0"]If[/color]
    8.  [color="#0000A0"]Next[/color] I
    9.  [color="#0000A0"]End[/color] [color="#0000A0"]If[/color]
    10. [color="#0000A0"]End[/color] [color="#0000A0"]Sub[/color]

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    No prob. Trojan.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width