好像解决不闪烁的话可以用"双缓冲技术",你正好趁这个机会研究一下,应该不难,我没遇到这个问题所以没研究,网上很多!
找了个例子,共同学习一下:
程序代码:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int x = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Interval = 10;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
DrawString("不闪烁,坚决不闪烁!");
}
private void DrawString(string text)
{
Rectangle rect = new Rectangle(0, 0, 800, 200);
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
Graphics g = Graphics.FromImage(bmp);
Font font = new Font("楷体_GB2312", 40);
SizeF sf = g.MeasureString(text, font);
float texty = (rect.Height - sf.Height) / 2;
float textx = (rect.Width - sf.Width) / 2;
LinearGradientBrush textbrush = new LinearGradientBrush(new PointF(0.0f, texty),
new PointF(0.0f, texty + font.GetHeight()), Color.DarkRed, Color.Red);
LinearGradientBrush backbrush = new LinearGradientBrush(new PointF(0.0f, 0.0f),
new PointF(0.0f, rect.Height), Color.SkyBlue, Color.White);
g.FillRectangle(backbrush, rect);
g.DrawString(text, font, new SolidBrush(Color.FromArgb(128, 0, 0, 0)), x + 2, texty + 2);
g.DrawString(text, font, textbrush, x, texty);
g.DrawString(text, font, new SolidBrush(Color.FromArgb(128, 0, 0, 0)), rect.Width + x + 2, texty + 2);
g.DrawString(text, font, textbrush, rect.Width + x, texty);
x -= 1;
if ((rect.Width + x) == 0) x = 0;
this.CreateGraphics().DrawImage(bmp, 0, 100);
}
}
}
[[it] 本帖最后由 shmilylee 于 2008-11-7 23:35 编辑 [/it]]