如何从自定义控件中完全删除继承的成员? [英] How do I completely remove an inherited member from my custom control?

查看:94
本文介绍了如何从自定义控件中完全删除继承的成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在使用.NET Framework为Windows应用程序编写基于Textbox控件的自定义控件,但遇到一个问题:我使用的代码可以很好地隐藏该属性中的某些继承属性网格,但仍可以对其进行操作.我想知道是否有可能从自定义控件中完全删除继承的成员.例如,我的控件隐藏了multiline属性,但我希望将其multiline标志永久设置为false.我的代码如下:

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:

<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




这样可以完美地隐藏该属性,以免用户代码对其进行编辑,但是,第二段代码似乎永远不会拾取更改的事件.我的意思是,当我在设计器模式下将自定义控件放到Windows窗体中时,控件上的小箭头(带有白色小方块和向东的黑色箭头的小箭头)仍然显示,从而允许我更改此属性单击时手动.有什么办法可以完全删除此属性?在这里的任何帮助将不胜感激!

[edit]代码块仅移至代码-OriginalGriff [/edit]




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]

推荐答案

任何继承的成员都无法删除.不是继承的原理.
您可以覆盖属性的虚拟方法或虚拟获取器或设置器.

同样,很简单,您可以用相同类型的新成员隐藏继承的成员,但是继承的成员将始终存在并且可以访问.

—SA
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


这篇关于如何从自定义控件中完全删除继承的成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆