Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I want to get the controls inside a tab page or group box which is in a windows forms in C#.

Ex:

foreach(Controls ctrl in tabPage1.controls)

{

if(ctrl is Label)

{

my code is here

}

}

Above code is the written by me for accesing Label Controls in my form.But i cant retreive Label Control Because it is inside the tabpage.

Is there any solution for this without specifying Groupbox1.Controls or tabpage1.controls

 

Plesae help me with the code

 

Thanks

Subash

Posted

Hmm.. Shouldn't it work to check in the loop if the ctrl has any controls in it, and then loop through them to? Perhaps create a recursive sub for it or something :)

 

Just a thought, I might be totally wrong:P hehe

Posted

As iMP said, you should get something like this:

 

vb.NET


Private Function CheckControls(ByVal control As Control) As Control
For Each c As Control In control.Controls
If c.Controls.Count > 0 Then CheckControls(c)
If TypeOf c Is Label Then
' Do something with c
Return c
End If
Next
Return Nothing
End Function
[/Code]

 

or C#

[Code]
private Control CheckControls(Control control)
{
foreach (Control c in control.Controls) {
if (c.Controls.Count > 0) CheckControls(c);
if (c is Label) {
// Do something with c
return c;
}
}
return null;
}
[/Code]

 

~DP

My Development System

Intel Core i7 920 @2.66Ghz

6 GB DDR3 SDRAM

Windows 7 Ultimate x64 & Windows Vista Home Premium x64 dual boot

GeForce GTX295 1.8 GB

3.5 TB HD

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...