窗体中的滚动字幕,向左右,及来回滚动

在窗体中添加一个label,一个Timer

在Timer事件中填写代码:

private void timer_Tick(object sender,EventArgs e) { label1.Left -=2; if(label1.Right<0) { label1.Left=this.Width; } }

注意:文字的滚动方向问题,向左则减,向右则加。

字幕来回滚动

代码如下 :

int LeftToRight = 0; private void timer1_Tick(object sender, EventArgs e) { if (label1.Right < 0) { label1.Left = this.Width; LeftToRight = 0; } if (label1.Left < 0) { label1.Left = 0; LeftToRight = 1; } if (label1.Right >= this.Width) { LeftToRight = 0; } if (LeftToRight == 0) label1.Left -= 10; else label1.Left += 10; }

你可能感兴趣的:(窗体中的滚动字幕,向左右,及来回滚动)