Custom graphics and CPU usage

sjn78

Well-known member
Joined
May 4, 2003
Messages
255
Location
Australia
I have made a user control that has a graphic for a backdrop. Its a JPG and I use the DrawImage function to apply it to the form. The image has regions, well more like a lame type of button, so when I move the mouse over them, a rectangle is drawn over them to give it a higlight effect. These regions are stored in an array of rectangles (about 20 of them). So when the mouse moves and the position is inside one of the rectangles, a rectangle is drawn over the button.

The problem I am having is the CPU usage. When the form is being display (doesnt have to be in focus), the CPU usage for the app runs at 50%. This will happen when the mouse is still.

Is there a way to get around this problem, so when the mouse isnt moving, it wont use as much CPU.

I have the AllPaintingInWmPaint and DoubleBuffer set to true. I was messing around with the Mouse Hover event to try to set a variable so when the Paint event ran, I could jump out of the event before any drawing started, and when the mouse moved again, set that variable back. I couldnt get this to work, the event seemed to only fire when nothing had been drawn onto the control.

Hope this makes a bit of sense to someone

Thanks
 
Feel free to delete or ignore or whatever you like...Found my problem. Stupidly, I was calling invalidate inside the paint event...a never ending loop!

Dont you feel stupid when you find an error like this!
 
Back
Top