为什么不改变标签文字! [英] why don't change label text !?

查看:70
本文介绍了为什么不改变标签文字!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi guy's

i使用此代码:



 T_Log.Tick + =(obj,args )= >  Lbl_Countdown.Text =(TimeSpan.FromMinutes( 1 ) - (DateTime.Now  -  startTime ))。ToString(  hh\\:mm \\:ss)+  @  
超时!
;





在标签中显示倒数计时器...当完成过程后,我想要更改标签文字但不要改变!?



 Lbl_Countdown.Text =   ; 
//
Lbl_Countdown.Text = 字符串 .empty;





我在做什么?

解决方案

在添加 Tick 方法和<$后,尝试输入

 T_Log.Enabled = true; 

p $ p> T_Log.Enabled = false;

当您的流程完成时,即

 Lbl_Countdown.Text =  ; 





[看到OP代码后编辑]



您的问题是您为同一个计时器注册了2个tick事件。很难调试,因为你已经为第二个事件使用了匿名函数。



帮自己一个忙,改变你的代码就像这样...移动匿名函数显式的

  private   void  T_Log_Tick_1( object  sender,EventArgs e)
{
Lbl_Countdown.Text =(TimeSpan.FromMinutes( 1 ) - ( DateTime.Now - startTime))。ToString( hh\\:mm \\:ss)+ @ ;
}

并在你的 Down_Counter 函数中使用

 T_Log.Tick + = T_Log_Tick_1; 



现在在

上放置一个断点Lbl_Countdown.Text =; 

运行你的程序,当它中断时使用F11来逐步执行...请注意,接下来发生的事情是 T_Log_Tick_1 然后执行,将标签的文本从空白直接更改为时间(00:00:00)



您不需要两个滴答事件。只需编写一个


hi guy's
i used this code :

T_Log.Tick += (obj, args) => Lbl_Countdown.Text = (TimeSpan.FromMinutes(1) - (DateTime.Now - startTime)).ToString("hh\\:mm\\:ss") + @"
timed out !";   



to display countdown timer in lable ... when process done , i want change lable text butt dont change !?

Lbl_Countdown.Text = "";
// or
Lbl_Countdown.Text = String.empty;



what i doing ?

解决方案

Try putting

T_Log.Enabled = true;

after you've added the Tick method and

T_Log.Enabled = false;

when your process has finished i.e. before

Lbl_Countdown.Text = "";



[EDIT after seeing OP code]

Your problem is that you have 2 tick events registered for the same timer. It is difficult to debug as you have used an anonymous function for the second event.

Do yourself a favour and change your code like this ...move the anonymous function into an explicit one

private void T_Log_Tick_1(object sender, EventArgs e)
{
    Lbl_Countdown.Text = (TimeSpan.FromMinutes(1) - (DateTime.Now - startTime)).ToString("hh\\:mm\\:ss") + @"";
}

and in your Down_Counter function use

T_Log.Tick += T_Log_Tick_1;


Now place a breakpoint on

Lbl_Countdown.Text = "";

Run your program, and when it breaks use F11 to step through ... notice that the next thing that happens is that T_Log_Tick_1 is then executed, changing the text of the label from blank straight back to a time again (00:00:00)

You don't need two tick events. Just code the one


这篇关于为什么不改变标签文字!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆