Phylum Posted August 12, 2003 Posted August 12, 2003 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? Quote
*Gurus* divil Posted August 12, 2003 *Gurus* Posted August 12, 2003 You can stop properties showing in the property grid by using a Browsable(false) attribute on them. You can't dynamically show and hide properties. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Phylum Posted August 12, 2003 Author Posted August 12, 2003 How would you stop an inherited property from showing up? Can you set attributes for a property you don't declare. Quote
*Experts* Volte Posted August 12, 2003 *Experts* Posted August 12, 2003 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:Protected Overrides Sub PreFilterProperties(ByVal properties As System.Collections.IDictionary) properties.Remove("MyProperty") End SubThen, 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. Quote
*Gurus* divil Posted August 13, 2003 *Gurus* Posted August 13, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Gurus* Derek Stone Posted August 13, 2003 *Gurus* Posted August 13, 2003 The more important consideration to make here is the validity of hiding or disabling properties, which you shouldn't even be attempting to do. It's poor object-oriented design and I strongly recommend re-evaluating your control's model. Quote Posting Guidelines
*Experts* Volte Posted August 13, 2003 *Experts* Posted August 13, 2003 I don't 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 it's just hidden from the prop browser, nothing has really been affected. Quote
*Experts* Nerseus Posted August 13, 2003 *Experts* Posted August 13, 2003 I think Derek was pointing out that dynamically hiding properties is a bad design decision. I had a similar requirement (sort of), but I didn't 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 don't remember what I did though - it was almost a year ago :) -Ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
*Gurus* Derek Stone Posted August 13, 2003 *Gurus* Posted August 13, 2003 The TextBox class has Multiline and AcceptsReturn properties. AcceptsReturn doesn't 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. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.