开发者

Can't change text of control

I wrote a simple winforms application which does some task every 30 seconds (using a timer). There is a function which is called each time its "time event" is raised.

In this function I am also trying to change some text that appears in some label. I try to do it by calling BeginInvoke - but this does not change the text.

Then I also try to call it by simple .Text = "some Text" - but t开发者_StackOverflow中文版his also did not work.

How can I change the control's properties?


You don't need to use BeginInvoke in this case. Form-based timers do not call from a separate thread. Simply replace your invoke code in the timer's tick event handler with a straightforward update of the label's text property. Like: myLabel.Text = "Timer event fired";


You need BeginInvoke only if you are working with threads. Otherwise following should work:

label.Text = "some Text";
Update();


You need only use the Timer control. And write your code in the Timer_tick event handler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜