.net 每x秒更改一次标签文本c#数组
我在表单上有一个标签,我想每3秒钟用字符串[]数组中的值更改一次标签。我想在字符串数组中无限旋转以更新标签.net 每x秒更改一次标签文本c#数组,.net,timer,label,.net,Timer,Label,我在表单上有一个标签,我想每3秒钟用字符串[]数组中的值更改一次标签。我想在字符串数组中无限旋转以更新标签 public void rotateMarqueText(string text) { string[] result = text.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); newsPostCount = result.Count
public void rotateMarqueText(string text)
{
string[] result = text.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
newsPostCount = result.Count();
new Task(() =>
{
foreach (var a in result)
{
DisplayText(a);
Thread.Sleep(3000);
return true;
}
}
).Start();
}
private System.Windows.Forms.Timer timer;
private void DisplayText(string x)
{
marqueText.Text = x;
}
它不会在列表中旋转确定。。。。你能记录关于线程。。。我很高兴舒尔能为您找到答案。。。从沃特我记得你需要开始这样的线程:
Thread myTh = new Thread();
while(....) { //put a condition...how much to run the thread ex: untill you pres a button
myTh.Sleep(2000); // sleeps for 2 sec
label.text = your value from array[i]
}
祝你有愉快的一天
public void rotateMarqueText(string text)
{
string[] result = "test\nme\n\please\n".Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
new Task(() =>
{
int i = result.Count();
while (true)
{
i++;
if (i > result.Count()) i = 0;
Task.Factory.StartNew(() =>
{
this.Invoke(new Action(() => DisplayText(result[i])));
});
Thread.Sleep(1000);
}
}).Start();
}
private void DisplayText(string x)
{
marqueText.Text = x;
marqueText.Refresh();
}
好的,明白了;-) 你的问题是什么,你试过什么,你到底需要什么帮助?