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

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

本文介绍了躲在自定义控件不需要的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于躲在自定义控件不需要的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 15:55