Click here to Skip to main content
Click here to Skip to main content

Rolling label

, 3 Oct 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Saloman Wu
Software Developer (Senior)
China China
No Biography provided

Comments and Discussions

 
Generalhello not work test sample Pinmemberhjozi4-Oct-08 2:56 
GeneralRe: hello not work test sample PinmemberSaloman Wu5-Oct-08 15:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 4 Oct 2008
Article Copyright 2008 by Saloman Wu
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid