PIC*_*ain 3 .net c# propertygrid gridsplitter visual-studio
我在我的C#项目中使用.NET PropertyGrid控件.
当包含网格的表单加载时,水平拆分器(将"设置"与"描述"分开)处于默认位置.如何在C#中以编程方式更改分割器的位置?
此代码基于代码项目中的文章(http://www.codeproject.com/KB/grid/GridDescriptionHeight.aspx),引入了两个修复和一些清理.
private void ResizeDescriptionArea(PropertyGrid grid, int lines)
{
try
{
var info = grid.GetType().GetProperty("Controls");
var collection = (Control.ControlCollection)info.GetValue(grid, null);
foreach (var control in collection)
{
var type = control.GetType();
if ("DocComment" == type.Name)
{
const BindingFlags Flags = BindingFlags.Instance | BindingFlags.NonPublic;
var field = type.BaseType.GetField("userSized", Flags);
field.SetValue(control, true);
info = type.GetProperty("Lines");
info.SetValue(control, lines, null);
grid.HelpVisible = true;
break;
}
}
}
catch (Exception ex)
{
Trace.WriteLine(ex);
}
}
Run Code Online (Sandbox Code Playgroud)
我在自己的项目中使用过它; 它应该适合你.