开发者

Form invalidate() in WinForms Application

开发者 https://www.devze.com 2022-12-30 02:12 出处:网络
i need to animate an object in c# windows application int l_nCircleXpos = 9, l_nCircleYpos = 0; private void Form1_Paint(object sender, PaintEventArgs e)

i need to animate an object in c# windows application

int l_nCircleXpos = 9, l_nCircleYpos = 0;

private void Form1_Paint(object sender, PaintEventArgs e)
{
    Graphics l_objGraphics = this.CreateGraphics();
    Pen l_circlePen = new Pen(Color.Blue);
    SolidBrush l_circleBrush = new SolidBrush(Color.Blue);
    l_objGraphics.DrawEllipse(l_circlePen, l_nCircleXpos, l_nCircleYpos, 30, 30);
    l_objGraphics.FillEllipse(l_circleBrush, l_nCircleXp开发者_开发知识库os, l_nCircleYpos, 30, 30);
    Pen l_rectPen = new Pen(Color.Red);
}

private void timer1_Tick(object sender, EventArgs e)
{
    l_nCircleXpos++;
    l_nCircleYpos++;
}

private void timer2_Tick(object sender, EventArgs e)
{
    Invalidate();
}

but in timer2 its invalidating the entire form. i need to invalidate the specific circle area only.

please help to do this in a better way


You can pass a Rectangle (or better, a Region) as a parameter to Invalidate, to invalidate only the area you need to refresh :

Region region = /* region you need to refresh */;
this.Invalidate(region);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号