改变的PropertyGrid的宽度左侧集合编辑/查看
-
06-09-2019 - |
题
任何与一个长字符串简单地引入了一个滚动条不可用的视图..
是集合编辑器的宽度由设计固定,并且可以在分离器被引入到这个真棒文稿?
解决方案
我还没有见过的方式定期PropertyGrid
要做到这一点,但如果你不介意多付,Visualhint有一个更发达发行的此处 - 或许试用它
这确实使用反射该作业;谨慎使用...
using System;
using System.Reflection;
using System.Windows.Forms;
class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Form form = new Form();
// this bar will control the splitter
ScrollBar sb = new HScrollBar {
Minimum = 10, Maximum = 200,
Dock = DockStyle.Bottom
};
// the grid we want to control
PropertyGrid grid = new PropertyGrid {
SelectedObject = form, Dock = DockStyle.Fill
};
// add to the form
form.Controls.Add(grid);
form.Controls.Add(sb);
// event to update the grid
sb.ValueChanged += delegate {
MoveSplitterTo(grid, sb.Value);
};
Application.Run(form);
}
static void MoveSplitterTo(PropertyGrid grid, int x) {
// HEALTH WARNING: reflection can be brittle...
FieldInfo field = typeof(PropertyGrid)
.GetField("gridView",
BindingFlags.NonPublic | BindingFlags.Instance);
field.FieldType
.GetMethod("MoveSplitterTo",
BindingFlags.NonPublic | BindingFlags.Instance)
.Invoke(field.GetValue(grid), new object[] { x });
}
}
不隶属于 StackOverflow