本帖最后由 QQ81867376 于 2012-06-26 12:14:28 编辑

解决方案 »

  1.   

    public class ControlTest : TextBox从这个控件继承
      

  2.   

    这个是你自己写的控件?
    直接设置控件的visible属性啊
      

  3.   

    写自定义控件的时候如果需要外部设定的属性记得写成public,然后再get事件里面写需要变更的值。如果你的控件是gdi+渲染的,记得在get事件里面重新画一下。
      

  4.   


    Devexpress 的图表统计,对应的属性就有这样的啊。
      

  5.   

    如果是自定义控件,只要继承ICustomTypeDescriptor接口,实现其方法即可解决,举例如下:
        public class ControlTest : System.Windows.Forms.Control, ICustomTypeDescriptor
        {
            List<string> propertyNames = null;//存放要显示的属性
            public ControlTest()
                : base()
            {
                propertyNames = new List<string>();
                propertyNames.Add("Size");
                propertyNames.Add("Location");
            }        #region ICustomTypeDescriptor 成员        AttributeCollection ICustomTypeDescriptor.GetAttributes()
            {
                return TypeDescriptor.GetAttributes(this.GetType());
            }        string ICustomTypeDescriptor.GetClassName()
            {
                return TypeDescriptor.GetClassName(this.GetType());
            }        string ICustomTypeDescriptor.GetComponentName()
            {
                return TypeDescriptor.GetComponentName(this.GetType());
            }        TypeConverter ICustomTypeDescriptor.GetConverter()
            {
                return TypeDescriptor.GetConverter(this.GetType());
            }        EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
            {
                return TypeDescriptor.GetDefaultEvent(this.GetType());
            }        PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
            {
                return TypeDescriptor.GetDefaultProperty(this.GetType());
            }        object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
            {
                return TypeDescriptor.GetEditor(this.GetType(), editorBaseType);
            }        EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
            {
                return TypeDescriptor.GetEvents(this.GetType(), attributes);
            }        EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
            {
                return TypeDescriptor.GetEvents(this.GetType());
            }        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
            {
                return this.FilterProperties(TypeDescriptor.GetProperties(this.GetType(), attributes));
            }        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
            {
                return this.FilterProperties(TypeDescriptor.GetProperties(this.GetType()));
            }        object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
            {
                return this;
            }        #endregion        #region 属性过滤        private PropertyDescriptorCollection FilterProperties(PropertyDescriptorCollection properties)
            {
                List<PropertyDescriptor> list = new List<PropertyDescriptor>();            foreach (string pname in propertyNames)
                {
                    var property = properties[pname];
                    if (property != null)
                    {
                        list.Add(property);
                    }
                }
                return new PropertyDescriptorCollection(list.ToArray(), true);
            }        #endregion
        }
    这样,你可以通过修改propertyNames里面的元素,来达到显示所需属性的目的。
      

  6.   

    在你的那个贴子里回复了。
    有一个扩展属性的东东。msdn讲的比较详细一些。微软的tooltip你搜一下就有。青龙白虎这个更不错。
      

  7.   


    public static void SetPropertyVisible(object entity, string attrName, bool visible)
    {
          Type type = typeof(BrowsableAttribute);
          PropertyDescriptorCollection props = TypeDescriptor.GetProperties(entity);
          AttributeCollection attrs = props[attrName].Attributes;
          FieldInfo info = type1.GetField("browsable", BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Instance);
          info.SetValue(attrs[type], visible);
    }通过反射处理,动态修改属性的Browsable值。
      

  8.   


    entiry 是表示 “要获取其属性的组件”吧,我调用的时候达不到目的,当设为false时候,把所有控件的属性都搞没有了,比如窗体,文本框的,这样太强了吧, public bool IsShowTextColor
            {
                get { return isShowTextColor; }
                set
                {
                    isShowTextColor = value;
                    //方案一
                    // SetPropertyVisible(value);                //this.UpdateStyles();
                    //this.Refresh();
                    //this.Update();                //方案二
                    SetPropertyVisible(this, "TextColor", value);
                }
            }
      

  9.   

    晕。首先你得先在你要动态调整的属性上加上 Browsable。private String name = String.Empty;
    [Browsable(true)]
    public String Name
    {
        get{ return this.name; }
        set 
        {
            if (this.name != value)
            {
                this.name = value;
            }
        }
    }
      

  10.   

    把其它属性也加上Browsable,否则会把整个类里的属性全改变。
      

  11.   

    加上确实是可以,但是和上面的是一样的效果,再改变对应值的时候,不能立马隐藏或者显示该属性。public bool IsShowTextColor
      {
      get { return isShowTextColor; }
      set
      {
      isShowTextColor = value;
      
      //this.UpdateStyles();
      //this.Refresh();
      //this.Update();  //方案二
      SetPropertyVisible(this, "TextColor", value);
      }
      }