Components.Count

  • Thread starter Thread starter sergey
  • Start date Start date
S

sergey

Hi,
I want show all components names on form when I press button. I wrote this
code button's.onclick event:

for (int i = 0; i<=this.components.Components.count - 1; i++)
MessageBox.Show(this.components.Components.ToString());

But when I click button, system show error message.

How can I show all components names on form?
 
like that:
for (int i = 0; i<=this.Controls.Count - 1; i++)
MessageBox.Show(this.Controls.Name);
 
Hi guy,
Thanks for your answer,

Your code shows components which parent is form. Is there any simple way to
show all objects (parent is not important) on form?


guy said:
like that:
for (int i = 0; i<=this.Controls.Count - 1; i++)
MessageBox.Show(this.Controls.Name);

sergey said:
Hi,
I want show all components names on form when I press button. I wrote this
code button's.onclick event:

for (int i = 0; i<=this.components.Components.count - 1; i++)
MessageBox.Show(this.components.Components.ToString());

But when I click button, system show error message.

How can I show all components names on form?
 
Hi,

you have to check if each control has controls like this:


void PrintControl( Control parent)
{
foreach( Control current in parent.Controls)
{
MessageBox.Show( current.ToString() );
if ( current.Controls.Count > 0 )
PrintControl( current );
}
}


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

sergey said:
Hi guy,
Thanks for your answer,

Your code shows components which parent is form. Is there any simple way to
show all objects (parent is not important) on form?


guy said:
like that:
for (int i = 0; i<=this.Controls.Count - 1; i++)
MessageBox.Show(this.Controls.Name);

sergey said:
Hi,
I want show all components names on form when I press button. I wrote this
code button's.onclick event:

for (int i = 0; i<=this.components.Components.count - 1; i++)
MessageBox.Show(this.components.Components.ToString());

But when I click button, system show error message.

How can I show all components names on form?

 
Back
Top