我这边试了一点闪烁都没有啊
using Timer = System.Threading.Timer;
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
this.DoubleBuffered = true;
InitializeComponent();
SetWavesValues();
timer1 = new Timer(RefreshWaves, null, TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(50));
}
private Timer timer1;
private int[] myWave = new int[1024];
void RefreshWaves(object? o)
{
try
{
SetWavesValues();
this.Invoke(this.Refresh);
}
catch { }
}
void SetWavesValues()
{
for (int i = 0; i < myWave.Length; i++)
{
myWave[i] = Random.Shared.Next(768);
}
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.Clear(Color.White);
using Bitmap bmp = new Bitmap(1024, 768);
using Graphics g = Graphics.FromImage(bmp);
using Pen pen = new Pen(Color.YellowGreen);
int i;
for (i = 0; i < myWave.Length - 1; i++)
{
g.DrawLine(pen, i, myWave[i], i + 1, myWave[i + 1]);
}
e.Graphics.DrawImage(bmp, 0, 0);
}
}
}
【 在 wjie 的大作中提到: 】
: 这个在创建form的时候已经使能了,但还是闪,无论是1ms还是100ms定时刷新都闪,感觉好像CPU忙不过来的样子
: this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw |ControlStyles.AllPaintingInWmPaint, true);
: this.UpdateStyles();
: ...................
--
FROM 113.66.230.*