private void timerMessage_Tick(object sender, EventArgs e)
{
timerMessage.Enabled = true;
Graphics g = lblMessages.CreateGraphics();//创健控件的Graphics类
g.Clear(Color.White);//以指定的颜色清除控件背景
Color Var_Color_Up = Color.Red;//设置前景色
Color Var_Color_Down = Color.Yellow;//设置背景色
Font Var_Font = new Font("宋体", 10);//设置字体样式
string Var_Str = lblMessages.Text;//设置字符串
SizeF Var_Size = g.MeasureString(Var_Str, Var_Font);//获取字符串的大小
PointF Var_Point = new PointF(5, 5);
RectangleF Var_Rect = new RectangleF(Var_Point, Var_Size);
LinearGradientBrush Var_LinearBrush = new LinearGradientBrush(Var_Rect, Var_Color_Up, Var_Color_Down, LinearGradientMode.Horizontal);
g.DrawString(Var_Str, Var_Font, Var_LinearBrush, Var_Point);
}
第二种
<pre name="code" class="csharp"> Color Var_Color_Up = Color.Red;//设置前景色
Color Var_Color_Down = Color.Yellow;//设置背景色
Font Var_Font = new Font("宋体", 10);//设置字体样式
string Var_Str = lblMessages.Text;//设置字符串
Graphics g = lblMessages.CreateGraphics();//创健控件的Graphics类
SizeF Var_Size = g.MeasureString(Var_Str, Var_Font);//获取字符串的大小
Brush brush = Brushes.Blue;
g.Clear(Var_Color_Up);//清除背景
string temp;
PointF p;
if (temp != Var_Str)//文字改变时,重新显示
{
p = new PointF(this.lblMessages.Size.Width, 0);
temp = Var_Str;
}
else
p = new PointF(p.X - 10, 0);//每次偏移10
if (p.X <= -Var_Size.Width)
p = new PointF(this.lblMessages.Size.Width, 0);
g.DrawString(Var_Str, Var_Font, brush, p);