-
What am I doing wrong here????
I want to change the one lable I have on screen. This code doesn't error, it just doesn't make the changes I want it to make. I've tried passing in the lable I'm working with, that worked! BUT why doesn't this work???
Thanks all....
Private Function ChangeLabel() As Label
Dim lblLabel As New Label
lblLabel.Text = "5342"
lblLabel.ForeColor = Drawing.Color.Red
Return lblLabel
End Function
Private Sub frmTest_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = "jrfksd"
Label1.ForeColor = Drawing.Color.Blue
Label1 = ChangeLabel()
End Sub
-
I've tried passing in the lable I'm working with, that worked!
Passing your Label as a parameter was the right way to do it. It worked. So why try something else???
But anyway...
------
... let us understand why your code does nothing.
What you are doing in your code is create a New Label. A new Label is invisible by default, so you have to set its Visible property to True in order to see it on the screen.
But even if you do so, you will have another surprise. A new Label is always located at position 0,0. You would thus have to also set it's position on the screen.
And you would have another surprise. You would see that you end up with 2 Labels. The old Label would still be there, but you would not be able to make any change to it.
A variable is not an object, it is simply a pointer, a way to communicate with the object. When you reassign a variable, the old object (the old Label in your case) stays in memory (the old Label stays on the screen), but your variable is now used to communicate with the new Label, with no way of reconnecting with the previous Label (not really true, but reconnecting would not be a straightforward task).
When you do
Code:
Label1 = ChangeLabel()
you simply connect the variable with the new Label. But since your new Label is not Visible, you think that nothing happened.
-----
I think that what you wanted to do is the following, which I thing you have tried:
Code:
Private Sub ChangeLabel(ByVal lblLabel As Label)
lblLabel.Text = "5342"
lblLabel.ForeColor = Drawing.Color.Red
End Sub
Private Sub frmTest_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = "jrfksd"
Label1.ForeColor = Drawing.Color.Blue
Label1 = ChangeLabel()
End Sub
Jacques Bourgeois
JBFI
http://www3.sympatico.ca/jbfi/homeus.htm
Similar Threads
-
Replies: 2
Last Post: 01-15-2010, 09:29 AM
-
Replies: 1
Last Post: 12-20-2005, 03:50 AM
-
By Alan Bell in forum .NET
Replies: 1
Last Post: 04-01-2002, 11:02 PM
-
Replies: 9
Last Post: 03-31-2002, 11:14 AM
-
By Richard Kalis in forum VB Classic
Replies: 1
Last Post: 03-20-2002, 12:31 PM
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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|