如何以编程方式调整 PropertyGrid 控件的水平分隔线?
我在我的 C# 项目中使用 .NET PropertyGrid 控件。
当加载包含网格的表单时,水平分隔符(将设置与描述分开)位于默认位置。如何在 C# 中以编程方式更改该拆分器的位置?
I am using a .NET PropertyGrid control in my C# project.
When the form containing the grid loads, the horizontal splitter (which divides the Settings from the Description) is at a default position. How do I change the position of that splitter programmatically in C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
此代码基于一篇文章 (http://www.codeproject.com/KB/ grid/GridDescriptionHeight.aspx)来自代码项目,其中包含两个修复和一些清理工作。
我在自己的项目中使用过它;它应该适合你。
This code is based off of an article (http://www.codeproject.com/KB/grid/GridDescriptionHeight.aspx) from The Code Project, with two fixes and some cleanup introduced.
I've used it in my own projects; it should work fine for you.
我现在必须做出一些调整才能使这项工作正常进行。以下适用于 .NET 6:
I had to make some adjustments to make this work now. The following works for .NET 6:
您无法使用 PropertyGrid 控件公开的公共方法和属性来做到这一点,或者至少我找不到任何有用的东西。
您可能会尝试使用反射来获取显示设置或说明的属性网格的子控件,并尝试以编程方式设置它们的高度;我猜分离器只是对接,设置它的位置不会改变任何东西。
使用调试器查看 PropertyGrid 的非公共成员应该可以帮助您了解控件的内部结构。
You cannot do that with the public methods and properties exposed by the PropertyGrid control, or at least I couldn't find anything useful.
You might try to use reflection to get the sub-controls of the property grid that display the settings or the description, and try to set their height programmatically; I guess that the splitter is just docked, and setting it position would not change anything.
Looking at the PropertyGrid's non-public members with the debugger should help you find out about the internal structure of the control.
这是 Matthew Ferreira 在 VB.Net 中的解决方案。谢谢马修,工作很愉快!
And here's Matthew Ferreira's solution in VB.Net. Thanks Matthew, works a treat!