开发者

WinForms - DataGridView Inherits style from GroupBox

开发者 https://www.devze.com 2022-12-22 11:23 出处:网络
I have a weird problem, and I don\'t know if this is the default behaviour of .Net DataGridView inside a GroupBox/TabControl.

I have a weird problem, and I don't know if this is the default behaviour of .Net DataGridView inside a GroupBox/TabControl.

I've 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've created a simple DataGridView, no font style at all, like thi开发者_如何转开发s:

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

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

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

My question is, can I disable this behaviour? Cause if I chage the DataGridView style outside the GroupBox and then drag it into, lost all the style.

Just for the record, this form has NO CODE at all.

Thanks in advance.


Try putting a panel in the group box, then setting the font property of the panel. This way the DataGridView will inherit the properties of the panel. Much easier than setting every font property of the DataGridView.


What you are experiencing is known as Ambient Properties. In short it is a mechanism where a control will "inherit" some property values from its parent, if the properties are not explicitly assigned to. I don't know of a way to prevent the behavior, other than assigning the wished values to the properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消