This is a follow-up question to: Need To Hide A Designer-Only Property From PropertyGrid For A .NET Winforms Control
I have replaced the default TypeDescriptorFilterService with my own implementation (so cool!), and the FilterProperties event handler is firing. I see how the previous question helped to hide those specific TableLayoutPanel properties.
Now I have a more general requirement on a project to hide certain properties. My current specific goal is to hide the "(Name)" property for my subclassed Windows Form object (my .NET project that leverages the designer manages object names internally and does not want to allow users to change or even see that value under certain conditions). To hide the Name property (actually shown as (Name) on the property grid) I added this code:
public bool FilterProperties(IComponent component, IDictionary properties)
{
if (component == null)
throw new ArgumentNullException("component");
if (properties == null)
throw new ArgumentNullException("properties");
if (typeof(MyExtendedDesignerObjects.Form).IsAssignableFrom(component.GetType()))
{
properties.Remove("Name");
return true;
}
IDesigner designer = this.GetDesigner(component);
if (designer is IDesignerFilter)
{
((IDesignerFilter)designer).PreFilterProperties(properties);
((IDesignerFilter)designer).PostFilterProperties(properties);
}
return designer != null;
}
MyMyExtendedDesignerObjects.Form inherits from System.Windows.Forms.Form. While my Form object (MyExtendedDesignerObjects.Form) is also an IDesignerFilter, I don't know how/where to wire-up its designer's PreFilterProperties event handler.
I think once I can get this pre-filter logic wired-up, then I can manage all of the property grid property-visibility goals I have for this project.
Thank you for reading.
Name property is a special property, it's added by a designer extender provider. You cannot hide it using this method, you need to find the extender provider which creates the
Nameproperty and replace it by another extender provider which creates theNameproperty havingBrowsable(false).But for rest of properties, you can hide them after
PostFilterProperties, by decorating them withBrowsable(false)Example 1 - Hide
LockedandTagpropertyPlease pay attention to the point:
Lockedis a design-time property butTagis a normal property.Override
FilterPropertiesmethod like this:Example 2 - Hide
NamepropertyIn the following example, in the
OnLoadedmethod of my custom designer surface, I have found theIExtenderProviderServiceand then I have removed the existingNameExtenderProviderandNameInheritedExtenderProviderand replaced them with my custom implementation. The custom implementations are essentially what I've extracted using reflector from system.design and just change theBrowsableattribute to false: