Using Variables inplace of Textbox Title
Posted: 5/6/2006 11:04:05 PMBy: Comfortably Anonymous
Times Read: 2,257
Likes: 0 Dislikes: 0
Topic: Programming: .NET Framework
Im working on a piece of code where there are over 300 text box's, now most of these are not visible until a certain requirement is met, is there a way to setup so i can use a variable name instead of the textbox's name to set the visible. Eg:
Private Sub DefendChanceLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DefendChanceLabel.Click
DefendChance.Visible = True
Count = +1
End Sub
/\ that is how i have todo it atm, for each one(plus i have to add checks to see if their visible etc - so another 5 lines of code per item)
This is how i was trying to get it to work
Private Sub ArtifactRarityLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ArtifactRarityLabel.Click
LabelValue = "ArtifactRarity" <-- this is the variable im talking about
Count = +1
End Sub
Private Sub BoxShow()
LabelValue.Visible = True <- this of course isnt working - and thats what im trying to achieve, any ideas?
Count = +1
End Sub
Private Sub DefendChanceLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DefendChanceLabel.Click
DefendChance.Visible = True
Count = +1
End Sub
/\ that is how i have todo it atm, for each one(plus i have to add checks to see if their visible etc - so another 5 lines of code per item)
This is how i was trying to get it to work
Private Sub ArtifactRarityLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ArtifactRarityLabel.Click
LabelValue = "ArtifactRarity" <-- this is the variable im talking about
Count = +1
End Sub
Private Sub BoxShow()
LabelValue.Visible = True <- this of course isnt working - and thats what im trying to achieve, any ideas?
Count = +1
End Sub
Rating: (You must be logged in to vote)
Discussion View:
By: Comfortably Anonymous
Times Read: 1,782
Likes: 0 Dislikes: 0
Topic: Programming: .NET Framework
Replies:
Re: Using Variables inplace of Textbox Title
Posted: 5/9/2006 7:18:32 PMBy: Comfortably Anonymous
Times Read: 1,782
Likes: 0 Dislikes: 0
Topic: Programming: .NET Framework
Here, try this (Maybe not the best implementation, threw this together quick). The trick is the 'Find' method.
To get this example to work, create a new VB Windows Form app and drag two labels (Label1 and Label2) onto it, then a button called Button1.
Let me know if you have any questions.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lbl As Label = Me.Controls.Find("Label1", True)(0)
lbl.Text = "Found #1"
Dim lbl2 As Label = Me.Controls.Find("Label2", True)(0)
lbl2.Text = "Found #2"
End Sub
End Class
To get this example to work, create a new VB Windows Form app and drag two labels (Label1 and Label2) onto it, then a button called Button1.
Let me know if you have any questions.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lbl As Label = Me.Controls.Find("Label1", True)(0)
lbl.Text = "Found #1"
Dim lbl2 As Label = Me.Controls.Find("Label2", True)(0)
lbl2.Text = "Found #2"
End Sub
End Class
Rating: (You must be logged in to vote)