65.9K
CodeProject is changing. Read more.
Home

Rolling label

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.54/5 (9 votes)

Oct 4, 2008

CPOL
viewsIcon

23062

downloadIcon

518

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;
            }
        }
     }