2010-06-20 22 views
0

我目前正在研究一個小應用程序,它可以在窗體頂部滾動消息 - 沒有什麼複雜的,但是我遇到了一個問題,我無法得到它與一個我的c#winform上的toolstriplabel。我目前通過使用正常標籤的下列方法工作,但toolstriplabels似乎沒有我需要滾動的.Left選項。這是我目前在計時器中使用的代碼。在ac#winform上使用toolstriplabel滾動文本

私人無效timer1_Tick(對象 發件人,發送System.EventArgs){

  this.label1.Left = this.label1.Left - 1; 
      if (this.label1.Left + this.label1.Width < 0) 
      { 
       this.label1.Left = this.label1.Width; 
      } 
     } 

有誰知道我可以使這項工作有一個工具條標籤的,我真的很喜歡這個滾動工具欄上的文字,以便用戶可以將其拖動到需要的地方?

感謝

回答

1

怎麼是這樣的:

namespace WindowsFormsApplication7 
{ 
    public partial class Form1 : Form 
    { 
     string _labelText = "Hello out there!"; 
     int _scrollOffset = 0; 

     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void timer1_Tick(object sender, EventArgs e) 
     { 
      string textToDisplay = _labelText.Substring(_scrollOffset++); 

      this.toolStripLabel1.Text = textToDisplay; 

      if (_scrollOffset > _labelText.Length) 
      { 
       _scrollOffset = 0; 
      } 
     } 
    } 
} 
+0

這是一個很好的例子! 謝謝... – Steve 2010-07-02 15:52:16