Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinForms tabpage not repainting on form resize

Is there a reason why a .NET WinForms TabPage doesn't fully repaint its background when I resize the Form? It should be completely white (in Windows 7), but a portion remains gray (SystemColors.Control, most likely). Whenever I hit the maximize button, currently visible TabPage background doesn't get redrawn. Also, if I resize it, I need to move the form past the screen boundaries in order for it to get painted.

The same thing happens if I minimize and then restore the form. In that case the TabPage background remains grey. Child controls are rendered properly (labels, for example, keep their white backgrounds).

I am using Windows 7 32-bit, .NET 3.5. Tab control was added using the Visual Studio designer, and contains a couple of labels and two text boxes. I haven't changed any native style flags related to paint messages.

[Edit]

I have created a test project, source is uploaded here.

This is how the window looks initially:

Form initial state

This is how the window looks after I minimize it and then restore it:

Minimized, then restored

Note the change in TabPage background color.

like image 270
Lou Avatar asked Sep 09 '12 10:09

Lou


1 Answers

I fixed this by adding a call to tabControl.Refresh() inside the tabControl's ClientSizeChanged method. Note that that's for the overall Tab Control and not each individual Tab Page.

like image 114
Phil Barr Avatar answered Oct 11 '22 12:10

Phil Barr