Re: PropertyGrid by martinfrompi
martinfrompi
Thu May 04 09:49:03 CDT 2006
Stefan Br=FCggemann wrote:
> Gabriel Lozano-Mor=E1n schrieb:
> > private void MoveSplitter(PropertyGrid propertyGrid, int x)
> > {
> > object propertyGridView =3D
> > typeof(PropertyGrid).InvokeMember("gridView", BindingFlags.GetField |
> > BindingFlags.NonPublic | BindingFlags.Instance, null, propertyGrid, nul=
l);
> > propertyGridView.GetType().InvokeMember("MoveSplitterTo",
> > BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Insta=
nce,
> > null, propertyGridView, new object[] { x });
> > }
> >
> > Eg:
> > MoveSplitter(myPropertyGrid, 100);
>
> Hello, i tried this, but it doesn't work.
> The Splitter always moves, but always to the same location.
> I tried to pass values for x from -1000 to 1000, but it doesn't
> have any effect.
> My PropertyGrid has no categories, no help, no toolbar, just a few
> properties. And I want to move the splitter :)
>
> Any Ideas? .NET 2.0 ?
>
Well b****r me!
I've just posted a "How do I do that" question, and you bring this
ancient thread to the top by replying to it!
Since my post, I've found that those nice people at NDoc have written a
class called "RuntimePropertyGrid" with (among other things) :
/// <summary>
/// Gets or sets the width of the label.
/// </summary>
/// <value></value>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int LabelWidth
{
get
{
Type type =3D this.GetType().BaseType;
BindingFlags flags =3D BindingFlags.Instance | BindingFlags.Public |
BindingFlags.NonPublic;
FieldInfo field =3D type.GetField("gridView", flags);
object gridView =3D field.GetValue(this);
type =3D gridView.GetType();
PropertyInfo prop =3D type.GetProperty("InternalLabelWidth", flags);
object InternalLabelWidth =3D
prop.GetValue(gridView,BindingFlags.GetProperty,null,null,null);
return (int)InternalLabelWidth;
}
set
{
Type type =3D this.GetType().BaseType;
BindingFlags flags =3D BindingFlags.Instance | BindingFlags.Public |
BindingFlags.NonPublic;
FieldInfo field =3D type.GetField("gridView", flags);
object gridView =3D field.GetValue(this);
type =3D gridView.GetType();
MethodInfo method =3D type.GetMethod("MoveSplitterTo",flags);
method.Invoke(gridView,new Object[]{value});
}
}
It looks very similar, but I don't know if it is different enough to
make it work again.