65.9K
CodeProject 正在变化。 阅读更多。
Home

滚动标签

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.54/5 (9投票s)

2008年10月4日

CPOL
viewsIcon

23598

downloadIcon

533

一个从右向左滚动文本的用户控件

引言

此控件从右向左循环滚动文本。

使用代码

您只需要设置以下两个属性即可。
Rolllabel.Text
Rolllabel.Speed
当速度设置为零时,它将停止滚动。

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

© . All rights reserved.