Hi,

Is there actually a way to get ALL the Controls on a Form? While using the
ControlCollection, it only returns the Controls that are directly on the
Form, not the controls that are on a (TableLayout)Panel etc.

I never found something like that, but it just would be nice in my opinion
:-)

Thanks,

Pieter

RE: Get ALL controls on a Form by PrasadMCAD

PrasadMCAD
Tue Sep 20 03:32:03 CDT 2005

Hi,
you can use following code snippet.

foreach (Control ctr in this.Controls)
{
if (ctr.HasChildren) // Check for Containder Control
{
//Controls on other control (e.g Panel)
}
}

Hope this will solve your problem

Prasad.


"DraguVaso" wrote:

> Hi,
>
> Is there actually a way to get ALL the Controls on a Form? While using the
> ControlCollection, it only returns the Controls that are directly on the
> Form, not the controls that are on a (TableLayout)Panel etc.
>
> I never found something like that, but it just would be nice in my opinion
> :-)
>
> Thanks,
>
> Pieter
>
>
>

Re: Get ALL controls on a Form by Lebesgue

Lebesgue
Tue Sep 20 03:31:52 CDT 2005

private ControlCollection res = new ControlCollection();
public void GetControls(Control parent)
{
if (! parent is Form)
{
res.Add(parent);
}

foreach(Control c in parent.Controls)
{
GetControls(c);
}
}

"DraguVaso" <pietercoucke@hotmail.com> wrote in message
news:udUq3ObvFHA.2512@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> Is there actually a way to get ALL the Controls on a Form? While using the
> ControlCollection, it only returns the Controls that are directly on the
> Form, not the controls that are on a (TableLayout)Panel etc.
>
> I never found something like that, but it just would be nice in my opinion
> :-)
>
> Thanks,
>
> Pieter
>
>



Re: Get ALL controls on a Form by Patrice

Patrice
Tue Sep 20 03:34:37 CDT 2005

You have to recurse into the controls of each control...

(Narrowed down to WindowsForms, controls)

--
Patrice

"DraguVaso" <pietercoucke@hotmail.com> a écrit dans le message de
news:udUq3ObvFHA.2512@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> Is there actually a way to get ALL the Controls on a Form? While using the
> ControlCollection, it only returns the Controls that are directly on the
> Form, not the controls that are on a (TableLayout)Panel etc.
>
> I never found something like that, but it just would be nice in my opinion
> :-)
>
> Thanks,
>
> Pieter
>
>



Re: Get ALL controls on a Form by Jeff

Jeff
Tue Sep 20 03:46:53 CDT 2005

On 20/09/2005 DraguVaso wrote:

> Hi,
>
> Is there actually a way to get ALL the Controls on a Form? While
> using the ControlCollection, it only returns the Controls that are
> directly on the Form, not the controls that are on a
> (TableLayout)Panel etc.


You could use a recursive procedure.

private sub GetControls(Control ctlParent, ref ArrayList al)
{
al.Add(ctlParent);
foreach(Control ctlChild in ctlParent)
GetControls(ctlChild, ref al);
}

Not tested, my development PC is off at the moment but something like
that should do it. Call it by setting up a new ArrayList and starting
with the Windows Form. If it doesn't recognise the Form as a control
you would need to start with:

private sub GetAllControls()
{
ArrayList al = new ArrayList();
foreach(Control ctl in frmMain)
GetControls(ctl, ref al);
}


--
Jeff Gaines

Re: Get ALL controls on a Form by Cor

Cor
Tue Sep 20 03:49:53 CDT 2005

Pieter

> Is there actually a way to get ALL the Controls on a Form? While using the
> ControlCollection, it only returns the Controls that are directly on the
> Form, not the controls that are on a (TableLayout)Panel etc.
>
Roughly done
\\\
Showall(me)
Private Sub ShowAll(ByVal parentCtr As Control)
For Each ctr As Control In parentCtr.Controls
Console.Write(ctr.name)
ShowAll(ctr)
Next
End Sub
///
I hope this helps,

Cor



Re: Get ALL controls on a Form by DraguVaso

DraguVaso
Tue Sep 20 04:06:44 CDT 2005

Thanks guys, I guess recursion will indeed be the only solution for this. I
think it's kind of weird there isn't a Collection that returns everything on
a form, but so be it, hehe :-)

Pieter

"Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote in message
news:eAtKuBcvFHA.708@TK2MSFTNGP10.phx.gbl...
> Pieter
>
> > Is there actually a way to get ALL the Controls on a Form? While using
the
> > ControlCollection, it only returns the Controls that are directly on the
> > Form, not the controls that are on a (TableLayout)Panel etc.
> >
> Roughly done
> \\\
> Showall(me)
> Private Sub ShowAll(ByVal parentCtr As Control)
> For Each ctr As Control In parentCtr.Controls
> Console.Write(ctr.name)
> ShowAll(ctr)
> Next
> End Sub
> ///
> I hope this helps,
>
> Cor
>
>



Re: Get ALL controls on a Form by Patrice

Patrice
Tue Sep 20 04:15:01 CDT 2005

Controls are organized as a tree. The form contains controls. Each control
can contains other controls that in turns etc...

This is what exposes the programming mdoel...


--

"DraguVaso" <pietercoucke@hotmail.com> a écrit dans le message de
news:%23PPFhKcvFHA.3548@tk2msftngp13.phx.gbl...
> Thanks guys, I guess recursion will indeed be the only solution for this.
I
> think it's kind of weird there isn't a Collection that returns everything
on
> a form, but so be it, hehe :-)
>
> Pieter
>
> "Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote in message
> news:eAtKuBcvFHA.708@TK2MSFTNGP10.phx.gbl...
> > Pieter
> >
> > > Is there actually a way to get ALL the Controls on a Form? While using
> the
> > > ControlCollection, it only returns the Controls that are directly on
the
> > > Form, not the controls that are on a (TableLayout)Panel etc.
> > >
> > Roughly done
> > \\\
> > Showall(me)
> > Private Sub ShowAll(ByVal parentCtr As Control)
> > For Each ctr As Control In parentCtr.Controls
> > Console.Write(ctr.name)
> > ShowAll(ctr)
> > Next
> > End Sub
> > ///
> > I hope this helps,
> >
> > Cor
> >
> >
>
>



Re: Get ALL controls on a Form by Herfried

Herfried
Tue Sep 20 05:42:26 CDT 2005

"DraguVaso" <pietercoucke@hotmail.com> schrieb:
> Is there actually a way to get ALL the Controls on a Form? While using the
> ControlCollection, it only returns the Controls that are directly on the
> Form, not the controls that are on a (TableLayout)Panel etc.

\\\
Private Sub RecurseControls(ByVal ctr As Control)
Debug.WriteLine(ctr.Name)
If ctr.HasChildren Then
For Each c As Control In ctr.Controls
RecurseControls(c)
Next c
End If
End Sub
.
.
.
RecurseControls(Me)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>