Jesper wrote:
[...]
Normally I put my updation of data shown in the controls on the usercontrol
in the Paint event handler of the usercontrol. When it comes to the
radiobuttons, a paint event for the usercontrol is fired whenever hovering
over the radiobuttons, making them impossible to change as they in the paint
event handler are set to reflect a given state.
Hoverver the problem is solved by putting the groupbox with the radiobuttons
on a panel on the usercontrol. The paint event for the control is now not
fired when hovering over it. Why?
I don't know specifically. I suspect it has something to do with the
Panel buffering the drawing of the contained controls, but I can't say
for sure.
That said, the more general issue here is the question of what you
should or should not do in a Paint event handler. The answer to that
question is:
Should do: draw stuff
Should NOT do: anything else
The fact that you're doing something other than drawing in your paint
handler is the root cause of the issue you're seeing. Even if you can
avoid the immediate manifestation of the problem by moving the controls
to a Panel inside the UserControl, that doesn't mean you've addressed
the basic problem. It just means you've covered it up somehow. Who
knows when it will come back or how?
The correct solution is to change the flow of data, so that you only
Paint in response to changes in the data, and any updates to that data
is done in direct response to changes in the UI that are supposed to
update the data, rather than waiting until you have to redraw the UI to
propagate those changes.
Pete