all groups > dotnet windows forms designtime > january 2005 >
You're in the

dotnet windows forms designtime

group:

Controlling properties at design time


Controlling properties at design time AviD
1/4/2005 5:07:03 AM
dotnet windows forms designtime:
Hi,
What will be the best way to manage, dynamically, during design time
properties of a control. For example, I would like to hide a certain property
description, when other property is assigned a certain value. I've tried
something like
Dim properties As PropertyDescriptorCollection =
TypeDescriptor.GetProperties(Controll) and going through the collection with
Dim mP As PropertyDescriptor, but it seems to me that not all the properties
are found in the collection, also, I can't get properties that reside under
a ExpandableObjectConverter. I need to find a method that will hide and
unhide a property descriptor.

--
Avi
American Society of Composers Authors and Publishers
New York, NY
RE: Controlling properties at design time v-jetan NO[at]SPAM online.microsoft.com (
1/5/2005 7:24:39 AM
Hi Avi,

Thanks for your posting!

Based on my understanding, you want to dynamically filtrate/add some
properties for certain control at design-time.

Actually, the standard way of manipulating the properties collection of
certain control is adding ControlDesigner/ComponentDesigner to the control,
then the control's design-time behavior will be controlled by this
ControlDesigner/ComponentDesigner.

We should override ControlDesigner/ComponentDesigner's several methods:
PreFilterProperties
PostFilterProperties
PreFilterAttributes
PostFilterAttributes
PreFilterEvents
PostFilterEvents

Rules:
The general rule to follow is to add or remove items(properties or events)
in the "PreFilter..." methods, and modify existing items(properties or
events) in the "PostFilter..." methods. Always call the base method first
in the PreFilter methods and call the base method last in the PostFilter
methods.

For a details explaination and samples, please refer to the good article
below:
"Writing Custom Designers for .NET Components"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/custdsgnrdotnet.asp
============================================================================
=====
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Re: Controlling properties at design time joeycalisay
1/6/2005 1:10:03 PM
Although they say that it's a bad design to have dependent properties, here
is how i got it worked before:

Implement ICustomTypeDescriptor on your component then override the
BrowsableAttribute of the affected properties returned from both
GetProperties method based on your test (dependence on other properties).



PropertyDescriptorCollection
System.ComponentModel.ICustomTypeDescriptor.GetProperties()

{

PropertyDescriptorCollection baseProps =


TypeDescriptor.GetProperties(this, attributes, true);



PropertyDescriptor[] props = null;

for (int i = 0; i < baseProps.Count;
i++)

{

if
(ShouldHideProperty(baseProps[i]))

{

if (props ==
null)

{


props = new PropertyDescriptor[baseProps.Count];


baseProps.CopyTo(props, 0);

}



props[i] =
TypeDescriptor.CreateProperty(


this.GetType(),


baseProps[i],


BrowsableAttribute.No);

}

}

if (props == null)

{

return baseProps;

}

return new
PropertyDescriptorCollection(props);

}


private bool ShouldHideProperty(PropertyDescriptor
pd)

{

if(this.independentProperty == somevalue
&& pd.Name == "DependentProperty") return true;

return false;

}




[quoted text, click to view]


AddThis Social Bookmark Button