using System;
using System
Collections
Generic;
using System
ComponentModel;
using System
Data;
using System
Drawing;
using System
Linq;
using System
Text;
using System
Windows
Forms;
namespace WindowsFormsApplication
{
public partial class Form
: Form
{
public Form
()
{
InitializeComponent();
}
private Label label = new Label();
public string text = "csdn baihe_
";
private void Form
_Load(object sender
EventArgs e)
{
this
label
Location = new Point(
);
this
label
Size = new Size(
);
this
Controls
Add(label);
this
label
Text = "";
this
timer
Enabled = true;
this
timer
Interval =
;
p = new PointF(this
label
Size
Width
);
}
PointF p;
Font f = new Font("宋體"
);
Color c = Color
White;
string temp;
private void timer
_Tick(object sender
EventArgs e)
{
Graphics g = this
label
CreateGraphics();
SizeF s = new SizeF();
s = g
MeasureString(text
f);//測量文字長度
Brush brush = Brushes
Black;
g
Clear(c);//清除背景
if (temp != text)//文字改變時
重新顯示
{
p = new PointF(this
label
Size
Width
);
temp = text;
}
else
p = new PointF(p
X
);//每次偏移
if (p
X <=
s
Width)
p = new PointF(this
label
Size
Width
);
g
DrawString(text
f
brush
p);
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/14349.html