How to hide a property at run time?  
Author Message
bg_blea





PostPosted: Windows Forms Designer, How to hide a property at run time? Top

Hi everybody.

I'm trying to hide a property "from" run time. It should be available only at design time. I know it has to do with attributes but which one




Windows Forms4  
 
 
Moayad Mardini





PostPosted: Windows Forms Designer, How to hide a property at run time? Top

What do you mean with "hide a property"

 
 
DMan1





PostPosted: Windows Forms Designer, How to hide a property at run time? Top

[Browsable(false)] Public Property BLAH


 
 
JRQ





PostPosted: Windows Forms Designer, How to hide a property at run time? Top

Can you give exactly why you need this to happen If you want something which is hidden and unsettable during run-time, but settable at design-time, I don't think it's possible.

 
 
Whatabohr





PostPosted: Windows Forms Designer, How to hide a property at run time? Top

The way to do this would be to not have it be an actual property on the class but to have it be a pseudo property which is provided by a designer for the class. Something like this:

public class MyButtonDesigner : ControlDesigner {
protected override void PreFilterProperties(System.Collections.IDictionary properties) {
base.PreFilterProperties(properties);
properties[_CustomPropertyDescriptor.Name] = _CustomPropertyDescriptor;
}
private bool _CustomProperty=false;
[DesignOnly(true)]
[DefaultValue(false)]
public bool CustomProperty {
get { return _CustomProperty; }
set { _CustomProperty = value; }
}
private static PropertyDescriptor _CustomPropertyDescriptor = TypeDescriptor.CreateProperty(typeof(MyButtonDesigner), "CustomProperty", typeof(bool));
}
[Designer(typeof(MyButtonDesigner))]
public class MyButton : Button { }


 
 
Chris Vega





PostPosted: Windows Forms Designer, How to hide a property at run time? Top

Try to use component designer attributes to "hide" your property from PropertyBrowser and TextEditor. Then you may want to check DesignMode (true if on DesignTime) in your property's getter and setter accessors:



[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public int MyHiddenProperty
{
get
{
if (!DesignMode)
{
throw new InvalidOperationException("Design time property only...");
}
return someValue;
}
set
{
if (!DesignMode)
{
throw new InvalidOperationException("Design time property only...");
}
someValue = value;
}
}



Hope this helps,

-chris