Results 1 to 11 of 11

Thread: [RESOLVED] Container

  1. #1

    Thread Starter
    Hyperactive Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    489

    Resolved [RESOLVED] Container

    I have a UC and inside it I have a picturebox. I need to place an object that is in the form and place it inside the picturebox that is in the usercontrol.

    I tried several things and it didn't work.
    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    2,531

    Re: Container

    Your UC would need some sort of public method that you pass the object to and then this method in your UC handles the process of placing it inside of the PictureBox, since the UC has access to the PictureBox.

  3. #3

    Thread Starter
    Hyperactive Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    489

    Re: Container

    Quote Originally Posted by OptionBase1 View Post
    Your UC would need some sort of public method that you pass the object to and then this method in your UC handles the process of placing it inside of the PictureBox, since the UC has access to the PictureBox.
    But this is what I'm trying....and I couldn't....

  4. #4

    Thread Starter
    Hyperactive Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    489

    Re: Container

    The way will be user SetParent ....

  5. #5
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,237

    Re: Container

    Have you tried the SetParent API? That should work...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  6. #6
    Addicted Member ISAWHIM's Avatar
    Join Date
    Jan 2023
    Posts
    170

    Re: Container

    This response seems more appropriate.
    https://www.vbforums.com/showthread....he-UserControl

    Your code also implies that you are trying to "stuff" "Picture1" into "Text1", which is actually impossible. You are, in essence, trying to send the Picture1 OBJECT, from the UC into the Text1 OBJECT on the Form1.

    Call Xcontrol.ContainerObject(Text1)
    which is trying to send the OBJECT(Form1.Text1), to the UC SUB...
    Here, you are trying to "Stuff" OBJECT(UserControl1.Picture1) into OBJECT(Form1.Text1), with a variant value as the bridge.
    Set Form1.Text1 = UserControl1.Picture1
    Code:
    Public Sub ContainerObject(oControl As Variant)
        Set oControl.Container = Picture1
    End Sub
    I personally tried a dozen ways to "load", "set", "transfer" the (object/textbox) from Form1 into (object/UC1.Picturebox), but I could not make anything work.

    Apparently you can't "put things into a UC", which it is not designed for. You also can't stuff a picture-box control into a textbox control, from any location. Especially not one from a UC, throwing it into a "Main form". (I assume you have that backwards anyways. Since you seem to describe "moving the text-box from Form1 into the picturebox in the UC", which is really not possible, I don't think.)

    I assume, to some point, you may need to use a GET, SET, LET property to manage any "controls", that you are trying to stuff into that UC. Or create a function to "load" a dynamic object within the UC itself, in the UC. Eg, to add the object, by handle, into the UC, so it can be destroyed and manipulated and have the exposed functions available or created for accessing the "adopted control", or "cloned control" with similar values.

    I guess you have to think of a UC as a whole new program. You can't throw an image-control into Notepad. A UC seems more like it's just a "window" into another "running program". A bit like a "browser-window" would be, if you added the BrowserControl to a vb6 project. You can't exactly throw an image-container into the HTML-view, but you can add an image to it.

    If your UC would create a NEW textbox, and you had a function to "get text" from the other text-box... Then you could unload the other textbox, at that point. (Or, possibly have the UC attempt to unload that object, by the passed handle?)
    Last edited by ISAWHIM; Mar 28th, 2023 at 06:05 PM.
    Please, chime-in on my latest WIP.
    I can use all the help I can get.
    [VB6 Game], (In Development), "Galactic-Bondsman"

  7. #7
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,750

    Re: Container

    Short answer, you can't.

    One thing is the Container and another thing is the Parent.

    You cannot change the parent from the form to the usercontrol. And you cannot change the Container to a control that is located on another Parent.

    You could try with the SetParent API, but this is a hack and could bring other unwanted effects (like focus issues).

    In your example the Parent of Picture1 is the UserControl and the Parent of Text1 is the form.

    The UserControl is ControlContainer, but for for Text1 to be able to be inside Picture1, Picture1 should be a control of the form and put inside the UC as a "contained control" and not as a "constituent control" (its Parent must be the form, not the UserControl).

  8. #8

    Thread Starter
    Hyperactive Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    489

    Re: Container

    Quote Originally Posted by Eduardo- View Post
    (like focus issues).
    This is another problem I'll have to work around .... but that's for later ...

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,112

    Re: Container

    A UserControl does everything a PictureBox can do (and more). Unless you have other controls on the UserControl I'm not sure why you have a PictureBox on it at all.

  10. #10
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,437

    Re: Container

    SetParent works fine:-
    Code:
    Option Explicit
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    
    Public Sub ContainerObject(oControl As TextBox)
        SetParent oControl.hWnd, Picture1.hWnd
    End Sub
    BTW I also tested this in both WinForms and WPF and they allow it with no problems. No need to even use SetParent. I think Windows can handle reparenting of controls just fine so I don't anticipate any ill effects using SetParet to achieve this in VB6.
    Last edited by Niya; Mar 29th, 2023 at 01:24 AM.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  11. #11

    Thread Starter
    Hyperactive Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    489

    Re: Container

    Quote Originally Posted by dilettante View Post
    A UserControl does everything a PictureBox can do (and more). Unless you have other controls on the UserControl I'm not sure why you have a PictureBox on it at all.
    Yes, it is necessary ... I need to place controls that are in a Parent usercontrol, and place them inside another Child usercontrol .....

    But the Setparent API solves it.... I just wanted to know if there are native means in VB6 itself.

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