Weird Label problem

  • Thread starter Thread starter Bruce Wolfe
  • Start date Start date
B

Bruce Wolfe

I having a problem programmatically changing the text for a Label
control.
No matter what I do, the text will remain what was defined in the
designer.
I've tried everything. After setting the Text property, I'm calling
Refresh on the form and/or the control. I've even called
Application.DoEvents(). IT WON"T CHANGE. I can even look at the Text
property in the debugger and it will actually show the text that I set
it to. What's up with this anyway? The form that this is happening to
is subclassed from another form class that I have defined. I'm about
to just draw the text myself but I would like to find an answer to
this. Thanks for any insight.
 
Hi Bruce,

A wild guess, are you changing the text before InitializeComponent is
called?
Are you changing a label with a different name than the one you expected
to change?
Do a filesearch on every occurances of the label and see if anything else
is changing it.
It would help if you could post some code.

Happy coding!
Morten Wennevik [C# MVP]
 
HI Bruce,

Can you post the code?
Maybe you are setting the Text in the wrong label,
You do not have to call Refresh or DoEvents.

Do you have access to the parent form? maybe the parent is handling the
TextChanged event of the label and returning it to the original value.

Do this, add a button to the form and on the onclick of it see the value of
the label, if it's the one you set I would bet on that you are updating the
wrong label.

Cheers,
 
Bruce Wolfe said:
I having a problem programmatically changing the text for a Label
control.
No matter what I do, the text will remain what was defined in the
designer.
I've tried everything. After setting the Text property, I'm calling
Refresh on the form and/or the control. I've even called
Application.DoEvents(). IT WON"T CHANGE. I can even look at the Text
property in the debugger and it will actually show the text that I set
it to. What's up with this anyway? The form that this is happening to
is subclassed from another form class that I have defined. I'm about
to just draw the text myself but I would like to find an answer to
this. Thanks for any insight.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
Back
Top