WinForms - DataGridView Inherits Style from GroupBox

I have a weird problem and I don't know if this is the default behavior of the .NET DataGridView in GroupBox / TabControl.

I created a new WinForm project from scratch and created a GroupBox (changed the text style). Like this:

alt text http://www.freeimagehosting.net/uploads/65f5f2762d.png

Then I created a simple DataGridView, without a font style, for example:

alt text http://www.freeimagehosting.net/uploads/09f55f951a.png

Then, in development mode, I dragged the DataGridView inside the GroupBox, and this kind of magic just happened:

alt text http://www.freeimagehosting.net/uploads/d0334132f0.png

My question is: can I disable this behavior? The reason is, if I use the DataGridView style outside the GroupBox, and then drag it, I lost the whole style.

For the record only, this form has NO CODE in general.

Thanks in advance.

+4
source share
2 answers

What you experience is called Environment Properties . In short, this is a mechanism in which a control will "inherit" some property values ​​from its parent if properties are not explicitly assigned. I don’t know a way to prevent behavior other than assigning the desired values ​​to the properties.

+2
source

Try placing the panel in the group box, and then set the font property of the panel. Thus, the DataGridView inherits the properties of the panel. Much easier than setting each property of the DataGridView font.

+13
source

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


All Articles