Invalidate properties

Phylum

Well-known member
Joined
Jun 20, 2003
Messages
105
Location
Canada
First Question:

I have created my own control. It has 3 properties: A, B, C.
If property A = TRUE then property B is inaccessable. Is this possible?

Second Question:

I have created an inherited control. Is there any way to block one of the inherited properties from showing up?
 
You can stop properties showing in the property grid by using a Browsable(false) attribute on them. You cant dynamically show and hide properties.
 
How would you stop an inherited property from showing up? Can you set attributes for a property you dont declare.
 
You need to create a custom forms designer for your component or control (make a class which inherits ComponentDesigner for non-visual components, ControlDesigner for standard components, ContainerControlDesigner for container controls, or ScrollableControlDesigner for container controls which support autoscrolling). In the class, override the PreFilterProperties method, and do this:
Code:
Protected Overrides Sub PreFilterProperties(ByVal properties As System.Collections.IDictionary)
    properties.Remove("MyProperty")
End Sub
Then, to set the designer to the appropriate control, give the <Designer(GetType(MyDesignerClass))> _ to your control (replace MyDesignerClass with the name of the designer you created) and all should be well.

At that point you can redefine the property yourself and set its Browsable attribute to false.
 
Alternatively, if possible, you can simply override the property (calling back to the base when required) and give it a Browsable(false) attribute in your derived version.
 
The more important consideration to make here is the validity of hiding or disabling properties, which you shouldnt even be attempting to do. Its poor object-oriented design and I strongly recommend re-evaluating your controls model.
 
I dont think there is anything wrong with hiding properties from the designer, as long as you can still access them through code. *Removing* inherited properties completely removes compatability with other objects which inherit the same base type. If its just hidden from the prop browser, nothing has really been affected.
 
I think Derek was pointing out that dynamically hiding properties is a bad design decision.

I had a similar requirement (sort of), but I didnt hide the other property, I just disabled it. Basically, if Property A is True then Property B must also be True. But if Property A is False, then Property B could be True or False. I dont remember what I did though - it was almost a year ago :)

-Ner
 
The TextBox class has Multiline and AcceptsReturn properties. AcceptsReturn doesnt magically disappear when Multiline is set to false. I could go on with further examples.

You have the option of ignoring properties, which is one thing, but hiding or disabling them is an entirely different practice which no one should partake in. Designer or no designer.
 
Back
Top