QUESTION ON: For Each Ctl In Me.Controls

A

Antony

Hi friends,

I have the following code in an MDI container (with 3 MDI
forms/children) with a button on the MDI container form.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Ctl As Control
For Each Ctl In Me.Controls
MsgBox(Ctl.Name)
Next
End Sub

Unfortunately when I click the button (Button1), all that is displayed
in the dialog boxes are "" and the name of the toolbar object.

I thin what I want is something like "For Each Ctl In Me.Children" but
alas, there is no collection ".Children". If my child forms are called
MDI1, MDI2, and MDI3, how can I modify this code to display in the
dialogbox MDI1, MDI2, and MDI3.

Thank you
Tony
 
A

Armin Zingler

Antony said:
Hi friends,

I have the following code in an MDI container (with 3 MDI
forms/children) with a button on the MDI container form.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim Ctl As Control
For Each Ctl In Me.Controls
MsgBox(Ctl.Name)
Next
End Sub

Unfortunately when I click the button (Button1), all that is
displayed in the dialog boxes are "" and the name of the toolbar
object.

I thin what I want is something like "For Each Ctl In Me.Children"
but alas, there is no collection ".Children". If my child forms are
called MDI1, MDI2, and MDI3, how can I modify this code to display in
the dialogbox MDI1, MDI2, and MDI3.

Browse the members of "Me". You'll find "MdiChildren".

=>
Dim Form As Form
For Each Form In Me.MdiChildren
MsgBox(Form.Name)
Next
 
J

Jay B. Harlow [MVP - Outlook]

Antony,
I thin what I want is something like "For Each Ctl In Me.Children" but
alas, there is no collection ".Children".
Have you tried Me.MdiChildren?

Or Me.OwnedForms?

I suspect MdiChildren is the one you want, while OwnedForms is useful in
similar cases.

Hope this helps
Jay
 
H

Herfried K. Wagner [MVP]

Hello,

Antony said:
I have the following code in an MDI container (with 3 MDI
forms/children) with a button on the MDI container form. [...]
I thin what I want is something like "For Each Ctl In
Me.Children" but alas, there is no collection ".Children".

\\\
Dim f As Form
Dim c As Control
For Each f In Me.MdiChildren
For Each c In f.Controls
...
Next c
Next f
///
 

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