WinForm实现状态栏跑马灯效果的方法示例
本文实例讲述了WinForm实现状态栏跑马灯效果的方法。分享给大家供大家参考,具体如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceWindowsFormsApplication1
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
}
privateLabellabel=newLabel();
publicstringtext="csdnbaihe_591";
privatevoidForm1_Load(objectsender,EventArgse)
{
this.label.Location=newPoint(149,13);
this.label.Size=newSize(134,16);
this.Controls.Add(label);
this.label.Text="";
this.timer1.Enabled=true;
this.timer1.Interval=500;
p=newPointF(this.label.Size.Width,0);
}
PointFp;
Fontf=newFont("宋体",10);
Colorc=Color.White;
stringtemp;
privatevoidtimer1_Tick(objectsender,EventArgse)
{
Graphicsg=this.label.CreateGraphics();
SizeFs=newSizeF();
s=g.MeasureString(text,f);//测量文字长度
Brushbrush=Brushes.Black;
g.Clear(c);//清除背景
if(temp!=text)//文字改变时,重新显示
{
p=newPointF(this.label.Size.Width,0);
temp=text;
}
else
p=newPointF(p.X-10,0);//每次偏移10
if(p.X<=-s.Width)
p=newPointF(this.label.Size.Width,0);
g.DrawString(text,f,brush,p);
}
}
}
更多关于C#相关内容感兴趣的读者可查看本站专题:《WinForm控件用法总结》、《C#窗体操作技巧汇总》、《C#数据结构与算法教程》、《C#常见控件用法教程》、《C#面向对象程序设计入门教程》及《C#程序设计之线程使用技巧总结》
希望本文所述对大家C#程序设计有所帮助。