如何更改 PropertyGrid 控件的边框颜色(或移除边框)? [英] How to change the border color (or remove the border) of a PropertyGrid control?

查看:74
本文介绍了如何更改 PropertyGrid 控件的边框颜色(或移除边框)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拥有标准的 WinForms 2.0 不幸的是只改变了单元格之间的内边界.

另外,我用ILSpy查看了PropertyGrid的源代码控制,但仍然没有发现任何对我有意义的东西.

我的问题是:

如何去除PropertyGrid控件的外边框或改变外边框的颜色?

更新 2012-05-04 - 解决方案(又名hack"):

基于 杰米的回答,我组装了一个可行的解决方案 (您可以从这里下载):

想法是将属性网格放在面板内,让面板夹住控件.

通过这种方法,我确实将剪切面板放入另一个面板中,该面板的 Padding 为1"(或任何您想要的边框),并为该面板设置了 BackColor 用作边框颜色(在我的示例中为绿色).

设置属性网格的Anchor为Left, Right, Top,Bottom",设置剪切面板的Dock为Full".

这很适合我的要求.我认为这是一种黑客行为,因为它消耗了我希望可以节省的两个面板的资源.

解决方案

这是另一种选择,因为我的第一个答案似乎不适合此特定控件.这是一个肮脏的伎俩,但应该有效:

在您的窗口或对话框中放置一个面板控件,比如大小为 100H x 300V.将属性网格放在面板中,位置为 -1,-1,大小为 102,302.

Having a standard WinForms 2.0 PropertyGrid control I'm looking for a way to either change the border color of the control or remove the border altogether.

I'm aware of the LineColor property which unfortunately only changes the inner borders between the cells.

Additionally, I used ILSpy to take a look at the source code of the PropertyGrid control and still found nothing meaningful to me.

My question is:

How to remove the outer border of a PropertyGrid control or change the color of the outer border?

Update 2012-05-04 - Solution (aka "hack"):

Based on Jamie's answer I assembled a working solution (which you can download from here):

The idea is to place the property grid inside a panel and let the panel clip the control.

With this approach, I did place the clipping panel into another panel that has a Padding of "1" (or whatever you want the borders to be) and gave this panel a BackColor that serves as the border color (green in my example).

Set the Anchor of the property grid to "Left, Right, Top, Bottom", set the Dock of the clipping panel to "Full".

This works well for my requirements. I would see this as kind of a hack since it consumes the resources of two panels which I hoped I could save.

解决方案

this is another alternative, as it seems that my first answer is not suitable for this particular control. This is a dirty trick but should work:

Put a Panel control in your window or dialog, let say with size 100H x 300V. Put the propertygrid inside the panel with position -1,-1 and size 102,302.

这篇关于如何更改 PropertyGrid 控件的边框颜色(或移除边框)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆