c# - 更改 PropertyGrid 左侧集合编辑器/ View 的宽度

标签 c# .net collections propertygrid

任何带有长字符串的内容都会简单地引入一个带有滚动条的不可用 View 。

集合编辑器的宽度是否由设计固定,是否可以将拆分器引入到这个很棒的演示文稿中?

最佳答案

我还没有看到使用常规 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 });
    }
}

关于c# - 更改 PropertyGrid 左侧集合编辑器/ View 的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/937365/

相关文章:

c# - 如何着手为 silverlight(桌面和网络)以及 WP7 创建应用程序?

java - JUnit - Java - 如何使用文件列表作为参数测试 void 方法

C#用不同的参数覆盖?

c# - 无法反序列化此 xml 的所有元素

c# - 如何将其转换为字典的字典

c# - 如何从保存在数据库中的字节数组设置CSS背景图像

c# - 无法加载文件或程序集 'System.Net.Http'

c# - Web 服务的 WSDL 中禁止的 XML 架构构造

java - Java TreeSet 中的给定元素处于什么级别?

c# - 将集合类型从接口(interface)更改为实现类