2011-11-30 43 views
0

我一直用Label控件她是示例代碼使用Label控件創建在C#中的winform循環滾動字幕文本

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

可能重複://stackoverflow.com/questions/5279136/marquee-in-vb-net) – V4Vendetta

回答

3

在timer1_Tick變化

if (xPos == 0) 

if (xPos <= 0) 

否則,如果this.Width是奇數,它不會工作。

0

我認爲你需要檢查是否XPOS < = 0,因爲如果XPOS = 1 XPOS後 - = 2個的XPOS將等於-1 [選取框中vb.net?](http的