MDI Children - Access Controls

  • Thread starter Brian P. Hammer
  • Start date
B

Brian P. Hammer

I have a MDI Children and want to access, lets say a label. I have seen in
other posts:

DirectCast(????, ????).MyLabel = "Label Text"

If MDIMain is the MDI and FormA is the MDI Child, how can I make it work?

Thanks,
Brian
 
G

Guest

Do you already have direct access to the MDI child? If the child you want is
the active child then you can use

MDIMain.ActiveMdiChild

otherwise you have to enumerate the children using the MdiChildren property
to find the MDI child you want. Once you have the MDI child it will be of
type Form.
Unless you know the name of the MDI child class then you won't be able to
directly access any of its child controls by name. If you do know the class
name then it would be

( (MyClass)childForm).MyLabel = ...

or in VB.NET
DirectCast(childForm, MyClass).MyLabel = ...

If you don't know the class name for the MDI child then you are stuck
enumerating its child controls using the Controls property. For each child
control you'll need to determine if it is the label you want. Once you have
it you can do the typecast to Label to get to the actual control.

Thus there are several different methods depending on what you already know:

childForm = MDIMain.ActiveMdiChild or,
childForm = enumerate MDIMain.MdiChildren until it is found

and

DirectCast(childForm, MyMDIClass).Label = ... or,
enumerate childForm.Controls until label is found and then cast to Label

Michael Taylor - 7/3/05
 
B

Brian P. Hammer

Thanks Taylor - Just what I was looking for. Lots of info for other
situations as well.
Regards,

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top