开发者

Scrolling text using a toolstriplabel on a c# winform

开发者 https://www.devze.com 2023-01-03 21:54 出处:网络
I am currently working on a little app that scrolls a message across the top of the form - nothing complex however i have ran into a issue where i can not get it to work with a toolstri开发者_如何学Cp

I am currently working on a little app that scrolls a message across the top of the form - nothing complex however i have ran into a issue where i can not get it to work with a toolstri开发者_如何学Cplabel on my c# winform. I currently have it working by the following method using a normal label but toolstriplabels dont appear to have the .Left option i require to make it scroll. This is the code i am currently using in a timer.

private void timer1_Tick(object sender, System.EventArgs e) {

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

Does anyone know how i can make this work with a toolstrip label as i would really like this scrolling text on a toolstrip so the user can drag it to where there require?

Thanks


How about something like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消