销售市场营销Win64首席执行官系统管理员质量保证数据库管理员Visual Studio .NET 2003Win32Visual Studio 2008Visual Studio 2005设计/图形架构师高级初级中级开发Visual StudioWindowsC#
滚动标签
一个从右向左滚动文本的用户控件

引言
此控件从右向左循环滚动文本。
使用代码
您只需要设置以下两个属性即可。
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; } } }