我想滚动显示Winforms标签中的文本。现在,我从此页面获得此代码:
public double getMostRain() {
double mostRain = rainfallStats[0];
for (int i = 0; i < rainfallStats.length; i++) {
if (rainfallStats[i] > mostRain) {
mostRain = rainfallStats[i];
}
}
return mostRain;
}
public double getLeastRain() {
double leastRain = rainfallStats[0];
for (int i = 0; i < rainfallStats.length; i++) {
if (rainfallStats[i] < leastRain) {
leastRain = rainfallStats[i];
}
}
return leastRain;
}
但是,此滚动文本到末尾,然后再次从标签末尾开始。我想使滚动像文本一样从头开始,而上一个文本进一步滚动
答案 0 :(得分:0)
变量:
Timer timer;
以您的形式初始化(public Form1()
):
timer = new Timer();
timer.Tick += new EventHandler(timer_tick);
timer.Interval = 150;//this will denote our timers update length. lower time = faster scroll
timer.Start();
然后添加此方法:
//in this method, lbl_scroll.Text is the string of the label we want to scroll.
//update it according to your project.
void timer_tick(object sender, EventArgs e)
{
string disecate = lbl_scroll.Text.ToString();
string starter = disecate.Substring(0, 1);
string step = disecate.Remove(0, 1);
string news = step + starter;
lbl_scroll.Text = news;
}