[英]Changing the width of PropertyGrid left-side collection editor/view
带有长字符串的任何内容都只会通过滚动条引入无法使用的视图。
集合编辑器上的宽度是否由设计固定,并且可以将分割器引入这个很棒的演示中吗?
我还没有看到使用常规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 });
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.