Hiding unwanted properties in custom controls

前端 未结 5 1066
一向
一向 2020-11-27 22:53

Is this the way to hide properties in derived controls?

public class NewButton : Button

...

[Browsable ( false )]
public new Con         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 23:13

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

提交回复
热议问题