Reputation: 7215
Winforms has a control titled PropertyGrid
. A display element of the PropertyGrid
is a description area. By default it displays the name of the selected property. Using attributes, a programmer can have it display other text.
I would like to remove it completely. It is taking up too much space and I don't need to have it display anything. I do not see any properties in the object model to remove it. Please post a solution for removing it.
Below is a screen shot of what I'm talking about. I would like to remove the area in red such that "PercentComplete" is at the bottom of the frame.
Upvotes: 8
Views: 2966
Reputation: 7215
Add the following to your code:
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")
{
var fieldInfo = control.GetType().BaseType.GetField("userSized",
BindingFlags.Instance |
BindingFlags.NonPublic);
fieldInfo.SetValue(control, true);
control.Height = height;
return;
}
}
}
And call it like this:
var progressTimerProperties = new ProgressTimerProperties();
propertyGridProgressTimer.SelectedObject = progressTimerProperties;
ChangeDescriptionHeight(propertyGridProgressTimer, 0);
Notice that '0'? It sets the height of the description area to 0, effectively removing it. If you want you can go the opposite direction and make it bigger to accommodate more text.
Upvotes: 1