473,804 Members | 3,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loop and addressing other controls

I am trying trying to loop through some label controls and setting some
properties for the labels I'm looping through. Currently I am addressing the
labels one at a time with IF...Then logic, like this:

If lblP1JoyUp.Bord erStyle = BorderStyle.Fix edSingle Then

lblP1JoyUp.Top = 10

lblP1JoyUp.Left = 10

lblP1JoyUp.Heig ht = 24

lblP1JoyUp.Widt h = 100

lblP1JoyUp.Visi ble = False

lblP1JoyUp.Back Color = Color.Transpare nt

lblP1JoyUp.Fore Color = Color.White

lblP1JoyUp.Font = frm1.Font

lblP1JoyUp.Bord erStyle = BorderStyle.Non e

frmLC.chkP1JoyU p.Checked = False

End If

It checks to see if a label is selected (Borderstyle.Fi xedSingle) and if so.
Changes a bunch of the labels properties. I don't have a problem changing
this code with my loop. However, the last line sets the status of a checkbox
on a different form. As you can see the checkbox name corresponds with the
labelname. I can't seem to figure out how to address the checkbox in my loop
code. Here is my loop code:

For Each ctrl As Label In Me.Controls

If TypeOf ctrl Is Label Then

If ctrl.BorderStyl e = BorderStyle.Fix edSingle Then

'Dim strlblCheck As CheckBox

'strlblCheck.Na me = "chk" & ctrl.ToString

ctrl.Top = 10

ctrl.Left = 10

ctrl.Height = 24

ctrl.Width = 100

ctrl.Visible = False

ctrl.BackColor = Color.Transpare nt

ctrl.ForeColor = Color.White

ctrl.Font = frm1.Font

ctrl.BorderStyl e = BorderStyle.Non e

'frmLC.strlblch eck.Checked = False

End If

End If

Next

You can see by the commented lines that I've tried a few things, but no
luck yet. What do I need to do here?

Thanks,

John
Nov 21 '05 #1
3 1319
There are 2 ways you can do this:

One is to loop through the controls in frmLC and find the one you are
looking for:

If lblP1JoyUp.Bord erStyle = BorderStyle.Fix edSingle then
Nov 21 '05 #2
John,

My favorite recursive control loop documentated in this message (typed so
watch typos)

I thought everything was in this answer you was asking.

I hope this gives an idea?

Cor
\\\\
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
doset(Me)
'It starts on a top place, can be any place by instance
'a button event, however it starts with Me which is
'the form itself which inherits from "Control"
'because it takes only the objects which inherits from "Control"
'it uses early binding
End Sub
'------------------
Private Sub doSet(ByVal thisCtr As Control)
Dim ctr As Control
'a placeholder for the reference of the object is created
For Each ctr In thisCtr.Control s
'The first time each (parent)control on a form
If TypeOf ctr Is Label
'Look if the "Control" is a label
ctr.text = "This you can do for every property from that label
End if
doSet(ctr)
'check if the control has children and do for that the same
Next
End Sub
///
Nov 21 '05 #3
* "jcrouse" <me> scripsit:
It checks to see if a label is selected (Borderstyle.Fi xedSingle) and if so.
Changes a bunch of the labels properties. I don't have a problem changing
this code with my loop. However, the last line sets the status of a checkbox
on a different form. As you can see the checkbox name corresponds with the
labelname. I can't seem to figure out how to address the checkbox in my loop
code.


\\\
Private Function FindControl( _
ByVal ControlName As String, _
ByVal CurrentControl As Control _
) As Control
Dim ctr As Control
For Each ctr In CurrentControl. Controls
If ctr.Name = ControlName Then
Return ctr
Else
ctr = FindControl(Con trolName, ctr)
If Not ctr Is Nothing Then
Return ctr
End If
End If
Next ctr
End Function
///

Usage:

\\\
DirectCast(Find Control("Button 1", Me), Button).Enabled = False
///

Notice that the procedure listed above is "slow", if you have to access a
lot of controls by name very often, you should store references to them in a
'Hashtable' object. You can use the name of the control as key:

\\\
Private m_Controls As New Hashtable()
///

Adding a control:

\\\
Dim DynamicPictureB ox As New PictureBox()
DynamicPictureB ox.Name = "PictureBox 1"
m_Controls.Add( DynamicPictureB ox.Name, DynamicPictureB ox)
///

Looking for a control:

\\\
Dim p As PictureBox = DirectCast(m_Co ntrols.Item("Pi ctureBox1"), PictureBox)
///

Removing a control:

\\\
m_Controls.Remo ve("PictureBox1 ")
///

Sometimes it's even better to add the control to an array. This will allow
fast and easy index-based access to the control references:

\\\
Dim MyLabels() As Label = {Label1, Label2, ..., Label10}
///

Access by 'MyLabels(0)' to 'MyLabels(9)'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4

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

Similar topics

4
3712
by: Ryan Ternier | last post by:
Thanks for the previous help guys! I got my list box issue working, but now i'm trying to loop through all the items in my page. I want to find each listbox, once I do i strip the ID down to find what I need so I can populate a DB. lstTest is dim'd as a ListBox, and I thought I could just do:
4
6379
by: sck10 | last post by:
I changed my aspx page to use a master page. The problem is that I can no longer loop through the controls on the content page. My question is how do you loop through the controls on the master page and how do you loop through the controls on the content page when the content is inside the ContentHolder control? Below is an example of the control loop before using a master page. Sub FindControlsInWebForm() Dim strValue As String = ""
3
1328
by: Kezza | last post by:
Hi There.. I have dynamically created some textbox and checkbox controls by adding them to a panel. Now I would like to get the values out. I have created a for each loop that I can see the controls Unique ID with. But I for the life of me can't figure out how to see the value the control is storing. Could somebody please help me. I'm thinking that I might need to use something like "findcontrol", but this wouldn't make sense to me. ...
8
2530
by: dominique | last post by:
Hi, Is it possible (in vb.net with WinForms) to loop throw controls inside a container (form or panel) sorting the controls on a property (.tabindex for example) ? My problem : on several forms (or panels), i have many controls (inherited controls from base controls : MyTextbox, MyCombobox ..). I add a new property on these controls : .BeginningGroup (boolean : yes or no).
3
1183
by: JebBushell | last post by:
I am unable to configure the addressing for images so that I can see them in a) the VS 2003 IDE, b) the site as hosted on my local machine, and c) the site as hosted in production. As an example, I have an <asp:image...> on the same page as an <IMG...>. Both controls are specified to display the same image file. However, in order to see both render image at the same in development, I need to address one as ../ and the other as ./ I...
5
1464
by: Ed Jay | last post by:
I have a switch statement that controls which of several containers is displayed or not. It currently looks like: function showHelp(n) { show('vhelp'); //makes parent container visible switch (n){ case 0: show('image0');hide('image1');hide('image2');...;hide('imagem'); break; ..
16
3549
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of instructions which can sure be optimized away is the check for the break condition, at least within the time where it is known that the loop will not reach it. Any idea how to write such a loop? e.g.
0
1335
by: gerritmitchell | last post by:
Hi, I have a situation where I need to send a SOAP message from a receiver through multiple intermediaries and then to an ultimate receiver. The intial sender will tell the intermediary where to send the message to next within the service chain. SOAP targeted headers and SOAP roles seem to suppor this quite well. My question is can this be used in conjunction with WS-Addressing? Meaning can I send a WS-Addressing compliant message...
1
4098
by: =?Utf-8?B?dWx0cmFuZXQ=?= | last post by:
We have a client that uses .Net that needs to work against our Java (xfire) based WS. My question is: how can a .Net (C#) WS client be configured to not send WS-Addressing headers? The client in particular mentions having tried WSE 2.0, and WSE 3.0, and says there is no way to turn off WS-Addressing in a WS client, using those frameworks. I find that very hard to believe. There appears to be a problem w/ WS-Addressing headers in the...
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9588
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.