【问题标题】:Scrolling text using a toolstriplabel on a c# winform在 c# winform 上使用工具条标签滚动文本
【发布时间】:2010-06-20 09:20:16
【问题描述】:

我目前正在开发一个在表单顶部滚动消息的小应用程序 - 没什么复杂的,但是我遇到了一个问题,我无法让它与我的 c# winform 上的工具条标签一起工作。我目前使用普通标签通过以下方法工作,但工具条标签似乎没有 .Left 选项,我需要让它滚动。这是我目前在计时器中使用的代码。

私有 void timer1_Tick(object 发件人,System.EventArgs e) {

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

有谁知道我如何使用工具条标签来完成这项工作,因为我真的很喜欢工具条上的滚动文本,以便用户可以将其拖动到需要的地方?

谢谢

【问题讨论】:

    标签: winforms


    【解决方案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;
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多