带有长字符串的任何内容都只会通过滚动条引入无法使用的视图。

集合编辑器上的宽度是否由设计固定,并且可以将分割器引入这个很棒的演示中吗?

最佳答案

我还没有找到使用常规PropertyGrid进行此操作的方法,但是如果您不介意付费,Visualhint会提供更先进的产品here-也许可以试用一下。



这使用反射来完成;谨慎使用...

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 });
    }
}

10-01 22:02
查看更多