Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Rolling label

0.00/5 (No votes)
3 Oct 2008 1  
A user control which is rolling text from right to left

Introduction

This control rolls text circularly from right to left.

Using the code

You just need to set two properties for it as following.
Rolllabel.Text
Rolllabel.Speed
When speed set to zero it will stop rolling.

    public partial class RollLabel : UserControl
    {
        private int m_speed = 5;

        public RollLabel()
        {
            InitializeComponent();
        }

        [Category("Appearance"),Browsable(true)]
        public string Text
        {
            get { return lblMsg.Text; }
            set { lblMsg.Text = value; }
        }

        [Category("Appearance")]
        public int Speed
        {
            get { return m_speed; }
            set
            {
                if (value < 0)
                {
                    throw new ArgumentOutOfRangeException();
                }
                m_speed = value;
            }
        }

        private void RollLabel_Resize(object sender, EventArgs e)
        {
            lblMsg.Top = (this.Height - lblMsg.Height) / 2;
            lblMsg.Left = this.Width;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            lblMsg.Left = lblMsg.Left - m_speed;
            if (lblMsg.Left <= -lblMsg.Width)
            {
                lblMsg.Left = this.Width;
            }
        }
     }
		

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here