This code is now in the form1 constructor.
if (filesRadar.Length > 0)
{
for (int i = 0; i < filesRadar.Length; i )
{
label2.Text = dates[i].ToString("ddd, dd MMM yyy HH':'mm");
}
}
I want to display the strings in dates when calling a method or something in the constructor and also in other places like when downloading finished. each time calling a method or enabling timer to display the strings in a loop in specific speed.
Now it's displaying but too fast then in the end displaying the last item only and it's not in loop.
CodePudding user response:
or enabling timer to display the strings in a loop in specific speed.
What's keeping you from doing that?...
Drop the timer on your form and set its Interval property to something reasonable. For instance, an interval of 1000 would mean it changes every second. Make sure the Timer is turned on (Enabled).
Now move the i variable out to class level and get rid of the for loop:
private int i = -1;
private void timer1_Tick(object sender, EventArgs e)
{
if (filesRadar.Length > 0)
{
i ;
if (i >= filesRadar.Length)
{
i = 0;
}
label2.Text = dates[i].ToString("ddd, dd MMM yyy HH':'mm");
}
else
{
label2.Text = ""; // optional?
}
}
CodePudding user response:
You do not need the if-statement, because the loop will only execute if there are items in the array:
for (int i = 0; i < filesRadar.Length; i )
{
label2.Text = dates[i].ToString("ddd, dd MMM yyy HH':'mm") Enviroment.NewLine;
}
CodePudding user response:
You can make this as a void method and you can call whenever you want i guess.
public void ReportTime()
{
for (int i = 0; i < filesRadar.Length; i )
label2.Text = dates[i].ToString("ddd, dd MMM yyy HH':'mm") Environment.NewLine;
}
