|
-
Apr 23rd, 2008, 12:49 PM
#1
Thread Starter
Junior Member
Dynamic Labels [RESOLVED]
I have searched this forum for hours for an answer to this question. There are many posts that are related to this but not exactly what i need to know...
What i am trying to do is after making labels dynamically how can i change the caption/text of each label indipendently from a button? The name of the dynamic labels is always changing and that info is retrieved from an xml file that can be changed so nothing can be static except for the button that initializes that label.text change...
here is the code i used to create the dynamic labels.
Code:
Dim lbl As New Label
Me.Controls.Add(lbl)
With lbl
.Name = ChangingVariable
.Parent = Me.Image1
.BackColor = Color.Transparent
.BringToFront()
.Top = 0
.Left = 0
.Width = 25
.Height = 55
End With
Last edited by Halisco; Apr 23rd, 2008 at 05:40 PM.
-
Apr 23rd, 2008, 01:19 PM
#2
Re: Dynamic Labels
Loop through the form's Control collection, until you find the one that you want, then you can re-set its caption.
-tg
-
Apr 23rd, 2008, 02:18 PM
#3
Thread Starter
Junior Member
Re: Dynamic Labels
 Originally Posted by techgnome
Loop through the form's Control collection, until you find the one that you want, then you can re-set its caption.
-tg
I'm not sure exactly what you mean. Can you please give me an example?
-
Apr 23rd, 2008, 02:26 PM
#4
Re: Dynamic Labels
roughly speaking, like this:
Code:
for each ctl as control in yourform.Controls
If ctl.NAme = "Some control's name" Then
ctl.caption = "Set your new caption
end
next
-
Apr 23rd, 2008, 02:37 PM
#5
Thread Starter
Junior Member
Re: Dynamic Labels
 Originally Posted by techgnome
roughly speaking, like this:
Code:
for each ctl as control in yourform.Controls
If ctl.NAme = "Some control's name" Then
ctl.caption = "Set your new caption
end
next
Thanks.... That doesnt work but i figured it out....
Code:
For Each ControlShowing In Image1.Controls
On Error Resume Next
If TypeOf ControlShowing Is Label Then
If ControlShowing.Name = "VolShow" Then
' DO NOTHING
ControlShowing.Text = "YES"
Else
ControlShowing.Text = " NO"
End If
End If
Next ControlShowing
-
Apr 23rd, 2008, 03:10 PM
#6
Re: Dynamic Labels
Good... it wasn't supposed to work. It was supposed to show the basics of ripping through the controls.
There's a problem with your code by they way....
-tg
-
Apr 23rd, 2008, 03:11 PM
#7
Thread Starter
Junior Member
Re: Dynamic Labels
 Originally Posted by techgnome
Good... it wasn't supposed to work. It was supposed to show the basics of ripping through the controls.
There's a problem with your code by they way....
-tg
Whats wrong with it? Its working....
-
Apr 23rd, 2008, 03:59 PM
#8
Re: Dynamic Labels
1. Turn Option Strict ON. It's not just helping your program run faster but also helping your write better code.
2. Do not use On Error Resume Next. Use Try/Catch block instead. But generally, you should avoid exceptions as much as you can.
-
Apr 23rd, 2008, 05:38 PM
#9
Thread Starter
Junior Member
Re: Dynamic Labels
 Originally Posted by stanav
1. Turn Option Strict ON. It's not just helping your program run faster but also helping your write better code.
2. Do not use On Error Resume Next. Use Try/Catch block instead. But generally, you should avoid exceptions as much as you can.
Thankyou very much,
I am just learning .NET I'm liking it so far. allot less code then VB6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|