我正在尋找一種滾動文本的有效方式,就像網頁術語中的選取框一樣。在C中滾動標籤#
我設法實現這一目標用了一段代碼我在網上找到:
private int xPos = 0, YPos = 0;
private void Form1_Load(object sender, EventArgs e)
{
//link label
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;
}
}
的代碼非常簡單,使用,一個計時器滴答事件。
它起初效果很好,但滾動3或4次後,它不會再出現。
有什麼我可以調整,使滾動無限?
還記得我們在90年代停止使用跑馬燈嗎? :) – DavidG 2014-09-22 16:21:08
當'xPos - = 2;'將位置減少到-1時,您會發生什麼? – 2014-09-22 16:21:13
爲什麼你不能在一個div和使用'選取框方向等... – MethodMan 2014-09-22 16:26:20