【问题标题】:Changing the width of PropertyGrid left-side collection editor/view更改 PropertyGrid 左侧集合编辑器/视图的宽度
【发布时间】:2009-06-02 00:03:12
【问题描述】:

任何带有长字符串的东西都只会引入一个带有滚动条的不可用视图..

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

【问题讨论】:

  • 编辑答案以显示基于反射的解决方案
  • 会接受答案,因为您似乎真的很忙并且活跃于 prop-grid 并且通常会使用 winforms 的东西 :) 谢谢.. 题外话,现在我开始做关于挂钩/搜索的噩梦使用类似方法从另一个属性网格收集视图属性网格.. 干杯。
  • 有关信息,您所描述的是模态 UITypeEditor,例如 CollectionEditor(以防万一有助于搜索...)

标签: c# .net collections propertygrid


【解决方案1】:

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

【讨论】:

  • 感谢 Marc.. 但我真的在寻找一个带有 250MB 框架的框架来拥有这个能力。
猜你喜欢
  • 1970-01-01
  • 2020-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多