在自定义控件中隐藏不需要的属性 [英] Hiding unwanted properties in custom controls
本文介绍了在自定义控件中隐藏不需要的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是在派生控件中隐藏属性的方式吗?
Is this the way to hide properties in derived controls?
公共类 NewButton : 按钮
...
[Browsable ( false )]
public new ContentAlignment TextAlign { get; set; }
这也会在设计器的属性"窗口中隐藏该属性,但我怎样才能在代码中隐藏该属性?
Also this hides the property in the Properties window in the designer but how can I also hide the property in code?
推荐答案
从代码中,你可以最接近地隐藏它,也许直接调用会很痛苦 - 请注意,即使隐藏它也是可调用的,并且这些都不能通过演员表:
From code, the closest you can do it to hide it, and perhaps make it a pain to call directly - note that even when hidden it is callable, and none of this will work past a cast:
// about the closest you can do, but not really an answer
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("just cast me to avoid all this hiding...", true)]
public new ContentAlignment TextAlign { get; set; }
就我个人而言,我不会打扰.它不健壮(只是投射).
Personally, I wouldn't bother. It isn't robust (just cast).
这篇关于在自定义控件中隐藏不需要的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文