Prevent Parent BackColor Inheritance Button

When I have a parent control that has BackColorbut SystemColors.Control, but I have buttons in that parent control that I want to draw on the system. However, when I do not change the buttons BackColoron the buttons, it is drawn with the color of the parent. When I change a button BackColorto a button SystemColors.Control, it is no longer drawn in the Windows theme.

alt text
The left version is c SystemColors.Control, and the right one is unchanged BackColor.

alt text
Exploded, it looks like this. Here you can see that the buttons have a solid background.

Any suggestions how can I fix this?

The effect in the image can be achieved by creating a new .NET 2.0 WinForms project and changing the constructor Form1to the following:

public Form1()
{
    InitializeComponent();

    var textBox = new TextBox();
    Controls.Add(textBox);

    var button = new Button { Text = "L", Width = 23, Height = 18, Left = -1, Top = -1 };
    textBox.Controls.Add(button);

    // Disable the line below to get the default behavior
    button.BackColor = SystemColors.Control;
}
+3
1

Windows 7, XP .., Application.EnableVisualStyles Main WinForms?

Windows 7 Aero , Application.EnableVisualStyles.

: button.UseVisualStyleBackColor = true; BackColor .

+3

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


All Articles