Hiding unwanted properties in custom controls

前端 未结 5 1071
一向
一向 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:16

    Why don't you make it private? It guarantees that ancestors will not see it. Edit: In this case you have to inherit a new class from the base and use your new class, which now hides ths property.

    public class MyTextBox: TextBox
    {
    ...
            private new ContentAlignment TextAlign
            {
              get { return base.ContentAlignment; }
              set { base.ContentAlignment = value; }
            }
    }
    

提交回复
热议问题