Click here to Skip to main content
15,890,185 members
Articles / Desktop Programming / Win32
Article

Rolling label

Rate me:
Please Sign up or sign in to vote.
2.54/5 (9 votes)
3 Oct 2008CPOL 22.8K   516   23   2
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)


Written By
Software Developer (Senior)
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalhello not work test sample Pin
hjozi4-Oct-08 2:56
hjozi4-Oct-08 2:56 
GeneralRe: hello not work test sample Pin
Saloman Wu5-Oct-08 15:33
Saloman Wu5-Oct-08 15:33 

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

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