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
Printable View
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
or something like that.Code:Picture1.Container
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
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?
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.
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?
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