躲在自定义控件不需要的属性不需要、自定义、躲在、控件

2023-09-03 01:21:58 作者:我亦王者

这是在派生的控件隐藏属性的方式?

Is this the way to hide properties in derived controls?

公共类NewButton:按钮

...

[Browsable ( false )]
public new ContentAlignment TextAlign { get; set; }

另外这个隐藏在设计师的属性窗口中的属性,但我怎么能还躲在code中的财产?

Also this hides the property in the Properties window in the designer but how can I also hide the property in code?

推荐答案

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