zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    一些前台技巧
    javascript中的面向对象
    vs.net 常用快捷键
    js和C#中的进制转换方法
    MFC中CDC相关图形,文本的一些使用方法(转)
    poj1505
    poj1401
    poj2533
    poj1504
    poj1384
  • 原文地址:https://www.cnblogs.com/hbb0b0/p/1885326.html
Copyright © 2011-2022 走看看