Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

  • *Experts*
Posted

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 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.

  • *Experts*
Posted
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.
  • *Experts*
Posted

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

"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*
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...