My form has a group box which contains two overlapping rectangles. The form\'s other controls are two sets of four numeric up down controls to set the rectangles\' colors. (nud
A group box, like any control, will paint itself when Windows sends it the WM_PAINT message. You can indeed use Control.CreateGraphics() to draw yourself, bypassing the normal paint logic. But that's not going to last and will randomly disappear when Windows decides that the control needs to repaint itself again. Which is obvious when you minimize the form and restore it. Less obvious on Vista and Win7 with Aero enabled, repaints are not necessary when your form is overlapped by another window. But it will be quite obvious on XP or with Aero disabled.
You cannot make this work reliably, you have to use the Paint event. Not your form's, the group box controls'. Call its Invalidate() method to force it to repaint when the color changes.
I suspect that painting in the Load
event is a little premature. Try painting in the Paint event.
Or:
Could you just use a couple of Panel controls, and set their background colors?