How to resize description area in PropertyGrid

From this article you can learn how to resize description area in PropertyGrid. Example shows use of reflection in order to dig to private members of PropertyGrid - not accessible in normal way.

Implementation is available both in C# and VB.Net languages. Use buttons below to switch language visibility.


System.Reflection namespace needs to be put in usings.

private static void ChangeDescriptionHeight(PropertyGrid grid, int height)
  if (grid == null) throw new ArgumentNullException("grid");
  foreach (Control control in grid.Controls)
   if (control.GetType().Name == "DocComment")
      FieldInfo fieldInfo = control.GetType().BaseType.GetField("userSized",
        BindingFlags.Instance |
      fieldInfo.SetValue(control, true);
      control.Height = height;

Private Shared Sub ChangeDescriptionHeight(grid As PropertyGrid, height As Integer)
  If grid Is Nothing Then
    Throw New ArgumentNullException("grid")
  End If
  For Each control As Control In grid.Controls
    If control.[GetType]().Name = "DocComment" Then
      Dim fieldInfo As FieldInfo = control.[GetType]().BaseType.GetField("userSized", 
	    BindingFlags.Instance Or BindingFlags.NonPublic)
      fieldInfo.SetValue(control, True)
      control.Height = height
      End If
End Sub

Syndicate content