P
pigeonrandle
Hi,
I hope this helps someone else because despite the fact that this is
obviously a common problem, after 5 hours of googling i found no exact
answer, just a load of 'do this, implement this, etc..' rant.
class LabelNoName : System.Windows.Forms.Label,
ICustomTypeDescriptor
{
#region ICustomTypeDescriptor Members
public String GetClassName()
{
return TypeDescriptor.GetClassName(this,true);
}
public AttributeCollection GetAttributes()
{
return TypeDescriptor.GetAttributes(this,true);
}
public String GetComponentName()
{
return TypeDescriptor.GetComponentName(this, true);
}
public TypeConverter GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
}
public EventDescriptor GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(this, true);
}
public PropertyDescriptor GetDefaultProperty()
{
return TypeDescriptor.GetDefaultProperty(this, true);
}
public object GetEditor(Type editorBaseType)
{
return TypeDescriptor.GetEditor(this, editorBaseType,
true);
}
public EventDescriptorCollection GetEvents(Attribute[]
attributes)
{
return TypeDescriptor.GetEvents(this, attributes, true);
}
public EventDescriptorCollection GetEvents()
{
return TypeDescriptor.GetEvents(this, true);
}
public PropertyDescriptorCollection GetProperties(Attribute[]
attributes)
{
return GetProperties();
}
public PropertyDescriptorCollection GetProperties()
{
PropertyDescriptorCollection pdcBase =
TypeDescriptor.GetProperties(this, true);
PropertyDescriptorCollection pdcNew = new
PropertyDescriptorCollection(null);
int iPropertiesIndex = 0;
while (iPropertiesIndex < pdcBase.Count)
{
PropertyDescriptor pd = pdcBase[iPropertiesIndex];
if (pd.DisplayName != "Name")
{
pdcNew.Add(pd);
}
iPropertiesIndex++;
}
return pdcNew;
}
public object GetPropertyOwner(PropertyDescriptor pd)
{
return this;
}
#endregion
}
#############################################################################################
Also, other properties (not added by the designer ie in brackets/
parentheses) can be removed using this technique which in fairness is
better documented:
[DesignerAttribute(typeof(LabelPreFilteredAttributesDesigner))]
class LabelPreFilteredAttributes : System.Windows.Forms.Label,
ICustomTypeDescriptor
{
}
class LabelPreFilteredAttributesDesigner :
System.Windows.Forms.Design.ControlDesigner
{
protected override void PreFilterProperties(IDictionary
properties)
{
properties.Remove("Dock");
}
//AND\OR
protected override void PostFilterProperties(IDictionary
properties)
{
properties.Remove("Location");
}
}
##########################################################################################
Less rant, more answers please,
James Randle.
I hope this helps someone else because despite the fact that this is
obviously a common problem, after 5 hours of googling i found no exact
answer, just a load of 'do this, implement this, etc..' rant.
class LabelNoName : System.Windows.Forms.Label,
ICustomTypeDescriptor
{
#region ICustomTypeDescriptor Members
public String GetClassName()
{
return TypeDescriptor.GetClassName(this,true);
}
public AttributeCollection GetAttributes()
{
return TypeDescriptor.GetAttributes(this,true);
}
public String GetComponentName()
{
return TypeDescriptor.GetComponentName(this, true);
}
public TypeConverter GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
}
public EventDescriptor GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(this, true);
}
public PropertyDescriptor GetDefaultProperty()
{
return TypeDescriptor.GetDefaultProperty(this, true);
}
public object GetEditor(Type editorBaseType)
{
return TypeDescriptor.GetEditor(this, editorBaseType,
true);
}
public EventDescriptorCollection GetEvents(Attribute[]
attributes)
{
return TypeDescriptor.GetEvents(this, attributes, true);
}
public EventDescriptorCollection GetEvents()
{
return TypeDescriptor.GetEvents(this, true);
}
public PropertyDescriptorCollection GetProperties(Attribute[]
attributes)
{
return GetProperties();
}
public PropertyDescriptorCollection GetProperties()
{
PropertyDescriptorCollection pdcBase =
TypeDescriptor.GetProperties(this, true);
PropertyDescriptorCollection pdcNew = new
PropertyDescriptorCollection(null);
int iPropertiesIndex = 0;
while (iPropertiesIndex < pdcBase.Count)
{
PropertyDescriptor pd = pdcBase[iPropertiesIndex];
if (pd.DisplayName != "Name")
{
pdcNew.Add(pd);
}
iPropertiesIndex++;
}
return pdcNew;
}
public object GetPropertyOwner(PropertyDescriptor pd)
{
return this;
}
#endregion
}
#############################################################################################
Also, other properties (not added by the designer ie in brackets/
parentheses) can be removed using this technique which in fairness is
better documented:
[DesignerAttribute(typeof(LabelPreFilteredAttributesDesigner))]
class LabelPreFilteredAttributes : System.Windows.Forms.Label,
ICustomTypeDescriptor
{
}
class LabelPreFilteredAttributesDesigner :
System.Windows.Forms.Design.ControlDesigner
{
protected override void PreFilterProperties(IDictionary
properties)
{
properties.Remove("Dock");
}
//AND\OR
protected override void PostFilterProperties(IDictionary
properties)
{
properties.Remove("Location");
}
}
##########################################################################################
Less rant, more answers please,
James Randle.