,我有一個簡單的問題: 我應該繪製在黑色背景上的白色顆粒(矩形),並將其從屏幕的一個到另一個水平移動。 我做到了,但問題是它閃爍太多(即不順利,即使速度很高,我可以很容易地看到每個動作和另一個的黑色背景)C#繪製我非常新的C#移動粒子
t.Interval = 1000/speed;
t.Tick += new EventHandler(t_Tick);
t.Start();
....
void t_Tick(object sender, EventArgs e)
{
//g.Clear(Color.Black);
g.DrawRectangle(new Pen(Brushes.Black, 20), r); //draw a black rectangle in the old position...20 is the thickness of the pen
r.X += move_x;
g.DrawRectangle(new Pen(Brushes.White, 20), r); //draw a white rectangle in the new position...20 is the thickness of the pen
if (r.X >= 1700) ///this means it reached the end of the screen
t.Stop();
}
我用g.Clear來清除圖形,但這也不起作用,所以在將它移動到新的位置之前,我在舊位置畫了一個黑色的矩形。
任何想法如何消除這種閃爍,甚至它以另一種方式嗎?
想你的窗體的'DoubleBuffered'屬性設置爲TRUE;? – Blorgbeard 2013-05-10 04:42:30
不,那該怎麼辦? – CSawy 2013-05-10 04:43:24
在窗體的設計視圖中,轉到屬性窗口(視圖 - >屬性窗口),並找到顯示「DoubleBuffered」的行,將該值更改爲「True」 – Blorgbeard 2013-05-10 04:44:53