Results 1 to 7 of 7

Thread: PictureBox as a container question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Posts
    17

    Talking

    When using a picturebox as a container, how do you reference the controls that it contains? Kind of like the Form.Controls collection.

    Thanks,
    trapper

  2. #2
    Guest
    Code:
    Picture1.Container
    or something like that.

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Smile

    Do you mean this?

    Code:
    Dim c As Control
    For Each c In Picture1.Container
        If TypeOf c Is Label Then Debug.Print "Label Control " & c
    Next

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Posts
    17

    I think it's something different

    I've always understood that picture1.container (with picture1 being a picturebox) returns the object that contains the picturebox, not a collection of the objects that the picturebox contains. Am I incorrect?

  5. #5
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    No, I don't think you need to refer to the PictureBox control even if it is a container for other controls.

    I have an array of CommandButtons on a PictureBox which is left-aligned on an MDI Form. I am able to reference the CommandButtons without referring to the PictureBox control.

    Of course, if you mean you want to iterate through all controls on a PictureBox, then I got your question wrong. Still I shall try to find out how this is done.

    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Posts
    17

    The second one

    Right. I meant that I only want to reference the controls contained by a specific picturebox.

    I had thought that I could create a collection of the controls contained in the picturebox when the form is loaded. Something like this:

    Dim Cntrl as Control
    Dim PictureCollection as Collection

    For Each Cntrl in Form.Controls
    If Cntrl.Container = picture1 then
    PictureCollection.Add Cntrl
    end if
    Next

    I think this would work. However, this seems awfully ineligant to me. Why would a picturebox or a frame be designed as a container if there were no simple way to reference the contained controls?

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Posts
    17
    Hmmm. That didn't quite work.
    I think I'm having trouble comparing the pointers for Cntrl.Container and picture1. Any more suggestions out there?

    Thanks,
    trapper

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