Home All Groups Group Topic Archive Search About

MDI Child Controls question

Author
4 Apr 2006 10:15 PM
Jerry Spence1
I have an MDI form with a number of MDIChildren. Each child is identical and
has a single PictureBox on it.

One of the child forms will be the active form. I need to code something
like this:

me.activeMDIChild.Picturebox1.Image = "C:\fred.jpg"

which of course I can't do. How do I refer to this control on the active
form?

Thanks

-Jerry

Author
4 Apr 2006 10:39 PM
Vijay
Ok there is something ActiveControl for each Form... not sure if you can use
that for a picturebox, because it can't get Focus like a textbox... so what
you can do is the below..

            Dim ChildControl As Control
            For Each ChildControl In Me.ActiveMdiChild.Controls
                If TypeOf ChildControl Is PictureBox Then
                    ' do your stuff here..
                End If
            Next



Show quoteHide quote
"Jerry Spence1" <jerry.spe***@somewhere.com> wrote in message
news:4432f01a$0$33925$ed2619ec@ptn-nntp-reader03.plus.net...
>I have an MDI form with a number of MDIChildren. Each child is identical
>and has a single PictureBox on it.
>
> One of the child forms will be the active form. I need to code something
> like this:
>
> me.activeMDIChild.Picturebox1.Image = "C:\fred.jpg"
>
> which of course I can't do. How do I refer to this control on the active
> form?
>
> Thanks
>
> -Jerry
>
Author
5 Apr 2006 5:40 AM
Stephany Young
Have a think about the Type (class) of the objects you are dealing with.

The type of Me.ActiveMDIChild is System.Windows.Forms.Form.  The type of the
object that is actually your MDIChild is whatever name you have given it and
is derived from System.Windows.Forms.Form.

You need to cast Me.ActiveMDIChild to whatever your class is before
attempting to access the controls on it.

e.g.:

  CType(Me.ActiveMDIChild, <myclass>).Picturebox1.Image = "C:\fred.jpg"


Show quoteHide quote
"Jerry Spence1" <jerry.spe***@somewhere.com> wrote in message
news:4432f01a$0$33925$ed2619ec@ptn-nntp-reader03.plus.net...
>I have an MDI form with a number of MDIChildren. Each child is identical
>and has a single PictureBox on it.
>
> One of the child forms will be the active form. I need to code something
> like this:
>
> me.activeMDIChild.Picturebox1.Image = "C:\fred.jpg"
>
> which of course I can't do. How do I refer to this control on the active
> form?
>
> Thanks
>
> -Jerry
>