使用Label控件在c#winform中创建循环选框文本
我使用Label控件创建了Marquee文本,她是示例代码
public partial class FrmMarqueeText : Form { private int xPos = 0, YPos = 0; public FrmMarqueeText() { InitializeComponent(); } private void FrmMarqueeText_Load(object sender, EventArgs e) { lblText.Text = "Hello this is marquee text"; xPos = lblText.Location.X; YPos = lblText.Location.Y; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { if (xPos == 0) { this.lblText.Location = new System.Drawing.Point(this.Width, YPos); xPos = this.Width; } else { this.lblText.Location = new System.Drawing.Point(xPos, YPos); xPos -= 2; } }
但是当第一次结束时,它没有继续工作。请帮助我!
在timer1_Tick中更改
if (xPos == 0)
至
if (xPos <= 0)
否则,如果this.Width
是奇数,它将无法工作。
我想你需要检查xPos是否<= 0.因为如果xPos = 1后xPos = 1你的xPos将等于-1