NETCF - Optimized Repaint (onPaint)

Posted by Nullstr1ng on Stack Overflow See other posts from Stack Overflow or by Nullstr1ng
Published on 2010-06-08T00:15:46Z Indexed on 2010/06/08 0:22 UTC
Read the original article Hit count: 645

Filed under:
|

Hi Guys,

I want to ask for suggestions on how to optimize a repaint in Compact Framework? GetHashCode() didn't help because it always return a different hash code.

Anyway, I have a program which you can drag and resize an object in run time. This object is a transparent object and it has a PNG image which also dynamically resize relative to object client size.

Though I noticed, (e.g. I have 4 transparent object and I'm dragging or resizing one) all 4 of them triggers OnPaintBackground even if the 3 are not moving. Another one when am just tapping on the one object .. it sill triggers onPaintBacground(). Anyway, I don't have a problem when this events get triggered.

What I like to do is optimization and that means I only have to repaint the object when it's necessary.

Can you guys please give a suggestions?

here's my pseudo C# code

Bitmap _backBuff;
onResize() {
   if(_backBuff != null) _backBuff.Dispose();
   _backBuff = new Bitmap(ClientSize.Width, ClientSize.Height);
   Invalidate();
}

onPaintBackground(e) /*have to use onPaintBackground because MSDN said it's faster*/ {
   using(Graphics g = Graphics.FromImage(_backBuff)) {
      g.Clear(Color.Black);

      // draw background
      ....some interface calling here
      ....and paint the background

      // draw alpha PNG
      .. get hDc
      .. paint PNG
      .. release hDc
   }

   e.Graphics.DrawImage(_backBuff,0,0);
}

Thanks in advance.

© Stack Overflow or respective owner

Related posts about compact-framework

Related posts about onpaint