473,466 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Find All Labels On Form

I am trying to write some code which will find all of the "Label" controls on
the form and change some property.

I started off by iterating over the Page.Controls and looking the the type
of each control to see if it is a label. This does not do the trick. I am
guessing that if a control contains other controls, I am not seeing them. Is
there a property which tells me if the control has other controls within in
it? Would I then itterate thought the collection of controls of that control
looking for labels and controls which contain other controls?

Thanks in advance for your assistance.
Aug 1 '06 #1
3 2340
You would have to write a little recursive routine that would go through
each controls collection of every control and look for Labels, and then do
something.

"Jim Heavey" <Ji*******@discussions.microsoft.comwrote in message
news:39**********************************@microsof t.com...
>I am trying to write some code which will find all of the "Label" controls
on
the form and change some property.

I started off by iterating over the Page.Controls and looking the the type
of each control to see if it is a label. This does not do the trick. I
am
guessing that if a control contains other controls, I am not seeing them.
Is
there a property which tells me if the control has other controls within
in
it? Would I then itterate thought the collection of controls of that
control
looking for labels and controls which contain other controls?

Thanks in advance for your assistance.

Aug 1 '06 #2
I am trying to write some code which will find all of the "Label" controls on
the form and change some property.

I started off by iterating over the Page.Controls and looking the the type
of each control to see if it is a label. This does not do the trick. I am
guessing that if a control contains other controls, I am not seeing them. Is
there a property which tells me if the control has other controls within in
it? Would I then itterate thought the collection of controls of that control
looking for labels and controls which contain other controls?

Thanks in advance for your assistance.
The control has a HasControls method. And yes, the Controls collection
contains only the direct children so you would have to iterate
recursively to find Labels (or whatever) at deeper levels.

Hans Kesting
Aug 1 '06 #3
Sample Code:

private void ChangeControlProperties(Control oParent)
{
int iItem;
Control oChild;
Label oChildLabel;

if ((oParent == null) || (!oParent.HasControls()))
{
return;
}

for (iItem = 0; iItem < oParent.Controls.Count; iItem++)
{
oChild = oParent.Controls[iItem];
if (!oChild.Visible)
{
continue;
}

if (oChildLabel is Label)
{
oChildLabel = (Label) oChild;
// Change Label Properties Here
}

ChangeControlProperties(oChild);
}
}

Call it as following:
ChangeControlProperties(Page);

Hth,
Ramu

Aug 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin O'Rourke | last post by:
All, I am hoping someone might be able to put me out of my misery and let me know if it is possible or not to dervie the name of an element in a form, based on its associated label, only knowing...
4
by: Dalan | last post by:
I have been using a module for printing labels in Access 97, and although it works fine, I would like to add a small enhancement to it. The module allows for setting the number of labels to print...
6
by: DebbieG | last post by:
I am creating a database for a small department in a university. Each student in their database can have 2 mailing addresses. They wanted mailing labels pulling just the 1st address. No problem....
7
by: Jared | last post by:
Here is my situation. I have multiple labels on a form but only certain ones will become visible while using the form. Depending on which check box(s) you pick, on another form, determines the...
2
by: Steve Barnett | last post by:
I've got a form on which there is a picture box with a picture in it. On top of that I place two labels and make their backgrounds transparent. What I expect to see is the picture showing through...
2
by: ooooscar | last post by:
I'd like to make an application to print labels. I have to print an image and text, the label size is 10cm x 5 cm. I'm wandering how to do it in c#. My first thought is to make an acrobat "form"...
7
by: Nemisis | last post by:
Hi everyone, Can anyone tell me if it is possible to pass in a property of an object into a sub, and within that sub, find out the name of the item that was passed along with the property name??...
3
by: wang frank | last post by:
Hi, I am a new user on Python and I really love it. I have a big text file with each line like: label 3 teststart 5 endtest 100 newrun 2345
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.