Alterando a largura de PropertyGrid lateral esquerda editor de recolha / vista
-
06-09-2019 - |
Pergunta
Qualquer coisa com uma longa seqüência simplesmente introduz uma visão inutilizável com uma barra de rolagem ..
é a largura em editor de coleção fixada pelo design e pode ser introduzido um divisor para esta apresentação impressionante?
Solução
Eu não vi uma maneira de fazer isso com PropertyGrid
regular, mas se você não se importa pagar, Visualhint tem uma oferta muito mais desenvolvida aqui -. talvez julgamento it
Este faz o trabalho usando a reflexão; uso com cautela ...
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 });
}
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow