我使用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;
}
}
但是第一次结束时,它还没有继续工作。请帮助我!
答案 0 :(得分:3)
在timer1_Tick中更改
if (xPos == 0)
到
if (xPos <= 0)
如果this.Width
为奇数,则无效。
答案 1 :(得分:0)
我认为你需要检查xPos&lt; = 0.因为如果xPos = 1后xPos = 1你的xPos将等于-1