Controls in a form

  • Thread starter Thread starter Alessandro Rossi
  • Start date Start date
A

Alessandro Rossi

My problem is to scroll all the controls in a form. The
problem is: If there are controls that contains still
others controls, that contains still others controls ecc...
how can i write an iteractive procedure to scroll all the
controls in the form?

Thank you so much
Alessandro Rossi
 
Hi Alessandro,

You should have no problem with that, I just did a test, if a control is
contained inside another control then its position is relative to its
parent, therefore when the parent is moved it will relocated.
I tried this:
In a form I placed a panel, inside the panel two buttons and one textbox,
when I change the Top property of the Panel containing the other controls
they scroll as expected.

Hope this help,
 
Maybe i've wrong to explain...
My problem is scroll the controls in a form, not move the
controls. If i write this code:
foreach (Control ctr in form1.Controls)
{
Dosomething
}

are examinated all the controls that had parent "Form1".
If in the form1 there is, for example, a panel with inside
others textboxes, these are not examinated because their
parent is the panel.

Thank you
Alessandro Rossi
 
Alessandro,

I still do not catch you, you say that you want to scroll the controls,
what do you mean with "scroll the controls" ?
An scroll action IS a move action, where you move the content of the
scrolled area up/down or right/left depending of the scroll movement.

Cheers,
 
Haa :)

Ok, basically what you can do is iterate in the Controls collection, and for
each Control see if that control's Controls has elements, if so iterate on
it, see that I'm making a deep first traversal, if you need a wide first you
will need a queue.

Here is the code for it:
void IterateControl(System.Windows.Forms.Control.ControlCollection
controls )

{

foreach(Control control in controls)

{

if ( control.Controls.Count > 0 )

IterateControl( control.Controls);

//do something with the control.

MessageBox.Show( control.Name);

}

}

private void button2_Click(object sender, System.EventArgs e)

{

IterateControl( Controls);

}

Hope this help,
 
Back
Top