Label 控件实现跑马灯效果
来源:互联网 发布:数据大魔王txt离线下载 编辑:程序博客网 时间:2024/04/29 01:31
public partial class LabelCt : System.Windows.Forms.Label
{
private PointF p;
private Font f = new Font("宋体", 10);
private Color c = Color.FromArgb(237, 232, 236);
private string temp;
public LabelCt()
{
Timer HelpTime = new Timer(); //实例化一个时间控件
HelpTime.Enabled = true; //让时间控件可用
HelpTime.Interval = 200; //时间间隔150毫秒
p = new PointF(this.Size.Width, 0);
HelpTime.Tick += new EventHandler(_Tick); //注册时间控件的Tick事件
}
private void _Tick(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
SizeF s = new SizeF();
s = g.MeasureString(Text, f); //测量文字长度
Brush brush = Brushes.Blue; //设置字体颜色
g.Clear(c); //清除背景
if (temp != Text) //文字改变时,重新显示
{
p = new PointF(this.Size.Width, 0);
temp = Text;
}
else
p = new PointF(p.X - 10, 0); //每次偏移10
if (p.X <= -s.Width)
p = new PointF(this.Size.Width, 0);
g.DrawString(Text, f, brush, p);
}
}
{
private PointF p;
private Font f = new Font("宋体", 10);
private Color c = Color.FromArgb(237, 232, 236);
private string temp;
public LabelCt()
{
Timer HelpTime = new Timer(); //实例化一个时间控件
HelpTime.Enabled = true; //让时间控件可用
HelpTime.Interval = 200; //时间间隔150毫秒
p = new PointF(this.Size.Width, 0);
HelpTime.Tick += new EventHandler(_Tick); //注册时间控件的Tick事件
}
private void _Tick(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
SizeF s = new SizeF();
s = g.MeasureString(Text, f); //测量文字长度
Brush brush = Brushes.Blue; //设置字体颜色
g.Clear(c); //清除背景
if (temp != Text) //文字改变时,重新显示
{
p = new PointF(this.Size.Width, 0);
temp = Text;
}
else
p = new PointF(p.X - 10, 0); //每次偏移10
if (p.X <= -s.Width)
p = new PointF(this.Size.Width, 0);
g.DrawString(Text, f, brush, p);
}
}
0 0
- Label 控件实现跑马灯效果
- WPF 实现跑马灯效果的Label控件,数据绑定方式实现
- 用flex 实现跑马灯效果控件
- 自定义UI控件实现跑马灯效果
- 自定义控件--跑马灯效果的实现
- Android中TextView控件的跑马灯效果实现
- label中的文字类似跑马灯的效果
- JavaScript实现跑马灯效果
- iOS实现跑马灯效果
- C#实现跑马灯效果
- C#实现跑马灯效果 .
- TextView实现跑马灯效果
- android实现跑马灯效果
- TextView实现跑马灯效果
- JS实现跑马灯效果
- JS 实现跑马灯效果
- js实现跑马灯效果
- TextView实现跑马灯效果
- fragment与activity及两个fragment之间的跳转实现
- Android:Ubuntu编译环境设置和编译
- Log
- oracle 创建小字段索引
- (三)逻辑运算指令和串操作指令
- Label 控件实现跑马灯效果
- RunLoop和线程的关系
- 欢迎使用CSDN-markdown编辑器
- c++: allocator, uninitialized_copy, uninitialized_fill_n
- SVN更新失败导致SVN被锁定
- “瀑布流式”图片懒加载代码示例
- 原型工具介绍
- SpringMVC表单标签简介
- Log4j 日志配置及初始化