.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

About get all Controls in a form

Posted By: subash     Posted Date: June 26, 2009    Points:2   Category :Windows Application
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

Responses
Author: Praveen             
Posted Date: June 26, 2009     Points: 5   

The Best way is have one Panel inside each tab area.

Now say you have panel1 inside Tab1 and in the Panel1 you have 10 controls

to retrieve all the label controls from Panel1

foreach (Control ctrl in Panel1.Controls)
{
Label lbl = ctrl as Label;
if (lbl != null)
{
// your logic goes here
}
}


Happy Coding!!!
Praveen



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend