PropertyGrid 왼쪽 컬렉션 편집기/보기의 너비 변경
-
06-09-2019 - |
문제
긴 문자열이있는 것은 단순히 스크롤 바로 사용할 수없는보기를 소개합니다 ..
컬렉션 편집기의 너비가 디자인에 의해 수정 되었으며이 멋진 프레젠테이션에 스플리터를 소개 할 수 있습니까?
해결책
나는 정기적으로 이것을 할 방법을 보지 못했습니다. 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 });
}
}
제휴하지 않습니다 StackOverflow