Reputation: 393
I added a picture box to a WinForms form and added a paint event. When I debug it, I see that the paint event is called twice.
How can I fix it?
Upvotes: 0
Views: 2723
Reputation: 613262
The picture box control is a relatively loose wrapper around Windows paint cycles and the WM_PAINT
event.
The WM_PAINT
event is a queued message that the system places in your applications message queue whenever it deems that a window's drawing surface is invalid. This can happen for many reasons:
Invalidate
which ultimately calls the Win32 InvalidateRect
function.So, the natural conclusion of this is that your picture box paint handler needs to be written under the assumption that it will be called multiple times.
Upvotes: 4
Reputation: 7817
The paint event is fired on every redraw which is quite often. The code in your paint event handler should be able to cope with it being called n-times.
Upvotes: 2