• 6 自定义控件之屏蔽控件的设计时属性


    1 屏蔽组建设计时属性                                                               
        1) 重载父类的属性,然后使用EditorBrowsable以及Browsable属性标记:                                                            
            例如,为了屏蔽基类的BackgroundImage属性,我们可以首先在子类中重载,然后为子类的BackgroundImage添加EditorBrowsable以及Browsable属性标记。                                                        
            [EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]                                                         
                public override Image BackgroundImage                                                         
                {                                                         
                    get                                                         
                    {                                                         
                        return base.BackgroundImage;                                                         
                    }                                                         
                    set                                                         
                    {                                                         
                        base.BackgroundImage = value;                                                         
                    }                                                         
                }                                                             
                EditorBrowsable(EditorBrowsableState.Never),  指示隐藏显示在智能编辑提示功能intelliSense;Browsable(false),指示隐藏显示在IDE控件属性页面。                                                        
                另外的一些情况,例如隐藏一些设计时不可见的属性,Browsable(false)也经常会被独立使用。                                                                                                        
        2)为控件编写一个designer, 在designer里面的PostFilterProperties方法中过滤掉不想要的属性。                                                           
            [Designer(typeof (MyDesigner))]                                                        
             public sealed class MyControl: System.Web.UI.WebControls.WebControl {}                                                        
            public class MyDesigner:System.Web.UI.Design.ControlDesigner                                                        
                {                                                        
                    public MyDesigner()                                                        
                    {}                                                        
                    protected override void PostFilterProperties( IDictionary Properties )                                                        
                    {                                                        
                        Properties.Remove( "BackgroundImage" );                                                        
                     }                                                        
                }             

    2 屏蔽效果

    image

  • 相关阅读:
    Wannafly 挑战赛12 E
    HIT ACM 2018春 week2 codeforces.com/gym/101652 题解
    Hihocoder [Offer收割]编程练习赛49 题目4 : 第K小先序遍历
    HDU
    ZOJ
    HYSBZ
    POJ
    HYSBZ
    POJ 2796 Feel Good 题解
    逆元基本知识
  • 原文地址:https://www.cnblogs.com/hbb0b0/p/1885326.html
Copyright © 2020-2023  润新知