Click here to Skip to main content
15,888,037 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
Hello,

I'm writing a custom control based on the Textbox control for a Windows application using the .NET Framework, but I've run into a problem: the code I'm using works fine for hiding some inherited properties from the property grid, but they can still be manipulated. I would like to know if it is possible to completely remove an inherited member from a custom control. For example, my control has the multiline property hidden, but I'd like to have it's multiline flag permanently set to false. My code is as follows:

VB
<Bindable(False)> _
<Browsable(False)> _
<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
<EditorBrowsable(EditorBrowsableState.Never)> _
Public Shadows ReadOnly Property Multiline() As Boolean
    Get
        Return False
    End Get
End Property
...

Protected Overrides Sub OnMultilineChanged(Byval e as System.EventArgs)
    Mybase.OnMultilineChanged(e)
    Mybase.Multiline = False
End Sub



This works perfectly hiding the property from being edited by user code, however, the second block of code seems to never pick up a changed event. What I mean is that when I drop the custom control into a windows form in designer mode, the little arrow (the one with the tiny white square and a black arrow pointing east) on the control still shows up, allowing me to change this property manually when clicked. Is there any way to completely remove this property? Any help here would be greatly appreciated!!

[edit]Code block move to just the code - OriginalGriff[/edit]
Posted
Updated 15-Jun-11 4:17am
v3

1 solution

No inherited members can be removed, ever. This is not how inheritance works.
You can override a virtual method or virtual getter or setter of a property.

Also, quite simply, you can hide an inherited member by a new member of the same type, but the inherited member will always be there and accessible.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900