Click here to Skip to main content
15,914,795 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hi guy's
i used this code :

C#
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 !?

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


what i doing ?
Posted
Updated 26-Aug-15 5:49am
v2
Comments
Andy Lanng 26-Aug-15 9:02am    
webform or winform?
ghasem110deh 26-Aug-15 12:10pm    
hi,
winform

1 solution

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
C#
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
C#
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
 
Share this answer
 
v2
Comments
ghasem110deh 26-Aug-15 12:15pm    
this full code butt not change lable text :
int a = 0;
int interval = 60;
void Down_Counter()
{
a++;
Settings.Default.Log_Counter = a;
Settings.Default.Save();
if (Settings.Default.Log_Counter == 5)
{
Pln_Login.Enabled = false;
User_Access.ShowBox(@"کاربر گرامی ، شما پنج بار متوالی نام کاربری و کلمه عبور
را اشتباه وارد کردید.", "عدم مجوز دسترسی !");
T_Log.Enabled = true;
var startTime = DateTime.Now;
T_Log.Tick += (obj, args) => Lbl_Countdown.Text = (TimeSpan.FromMinutes(1) - (DateTime.Now - startTime)).ToString("hh\\:mm\\:ss") + @"
پنجره ورود بمدت پنج دقیقه غیر فعال می باشد !";
}
}

private void T_Log_Tick(object sender, EventArgs e)
{
interval--;
if (interval == 0)
{
T_Log.Enabled = false;
Pln_Login.Enabled = true;
a = 0;
interval = 60;
Lbl_Countdown.Text = "";
}
}
CHill60 26-Aug-15 17:16pm    
I've updated my solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900