WinForms Tab Does Not Redraw When Resized

Is there a reason why .NET WinForms TabPage does not completely redraw its background when resizing a form? It should be completely white (on Windows 7), but the part remains gray ( SystemColors.Control , most likely). Whenever I click the maximize button, the current visible TabPage background TabPage not redrawn. In addition, if I resize it, I need to move the form off the screen so that it is colored.

The same thing happens if I minimize and then restore shape. In this case, the TabPage background remains gray. Child controls are displayed correctly (labels, for example, retain their white background).

I am using the 32-bit version of Windows 7, .NET 3.5. Tab management was added using the Visual Studio constructor and contains a couple of shortcuts and two text fields. I have not changed the flags of my own style associated with messages with paint.

[change]

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

This is what the window looks like:

Form initial state

This is what the window looks like after I hide it and then restored it:

Minimized, then restored

Notice the change in the background color of the TabPage .

+4
source share
3 answers

Ok, I decided that your problem can be solved by following these steps:

For tabPage set UseVisualStyleBackColor to False and just set its BackColor to the color you want, in this case White

Instead of snapping from all sides, just set the Dock to Fill . As a rule, do not set the size for labels; try only bindings for them.

+5
source

I fixed this by adding a call to tabControl.Refresh () inside the tabControl method of ClientSizeChanged. Note that this is for the general Tab control, not for each individual tab.

+6
source

This visual styles error has been fixed in .NET 4.0.

+2
source

Source: https://habr.com/ru/post/1433213/


All Articles