我自己的一个类:
public class ImageStyle{
     public Unit Width{get;set;}
     public Unit Height{...}
     public string CssClass{...}
     public int BorderWidth{...}
     public Color BorderColor{...}
}
我想加一个类似于Font的控件属性的类(ImageStyle)
在设计模式的属性窗口中
左边有一个加号图片可以展开,看到这个类的成员,
这样,就可以直接设置他的Width,Height等属性哎,Google上找了几天都没望 :(

解决方案 »

  1.   

    反编译工具,反编译服务器控件用到Font属性所标识的EditType是什么。
    在把那个EditType反编译看下。
      

  2.   

    不是很简单吗?
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.ComponentModel;public A : Component
    {
        public A()
        { 
            _iS = new ImageStyle();    // 先实例化一个ImageStyle。
        }
        public ImageStyle IS
        {
            set{ _iS = value; }
            get{ return _iS; }
        }    private ImageStyle _iS;
    }楼主把这段代码拷进去看看。
      

  3.   

    :( 这个我早想到了。
    vs2005能看,Font是FontInfo类,大致是这样的
    namespace System.Web.UI.WebControls
    {
        // 摘要:
        // Encapsulates the font properties of text. This class cannot be inherited.
        public sealed class FontInfo
        {
            // 摘要:
            // Gets or sets a value that indicates whether the font is bold.
            // 
            // 返回值:
            // true if the font is bold; otherwise, false. The default value is false.
            [DefaultValueAttribute(false)]
            [NotifyParentPropertyAttribute(true)]
            public bool Bold { get; set; }
            //
            // 摘要:
            // Gets or sets a value that indicates whether the font is italic.
            // 
            // 返回值:
            // true if the font is italic; otherwise, false. The default value is false.
            [DefaultValueAttribute(false)]
            [NotifyParentPropertyAttribute(true)]
            public bool Italic { get; set; }
      

  4.   

    这种在代码下肯定没错啊,但我要的效果是,在设计窗口里,直接可以在属性窗口里点,就像Font属性一样。如果像你这样,他显示的是被disabled的内容,显示的是他的类名如:NameSpace.ClassName
      

  5.   

    不好意思,上面的是回复 mapserver(杨东) 的。
      

  6.   

    // 测试类,其中包括自定义类属性
    public class Test
    {
    private MyCxpandableClass cc = new MyCxpandableClass();
    public MyCxpandableClass CC
    {
    get
    {
    return cc;
    }
    set
    {
    cc = value;
    }
    }
    }
    // 作为上下个类的属性的类,为了可展开编辑,扩展转换类(在后面)
    [TypeConverterAttribute(typeof(MyExpandableObjectConverter))]
    public class MyCxpandableClass
    {
    private int a;
    private float b;
    public int A
    {
    get
    {
    return a;
    }
    set
    {
    a = value;
    }
    }
    public float B
    {
    get
    {
    return b;
    }
    set
    {
    b = value;
    }
    }
    }
    // 类型转换类
    public class MyExpandableObjectConverter: System.ComponentModel.ExpandableObjectConverter
    {
    public MyExpandableObjectConverter()
    {
    }
    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
    {
    if (sourceType == typeof(System.String))
    return true; return base.CanConvertFrom (context, sourceType);
    }
    public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
    {
    if (destinationType == typeof(MyCxpandableClass))
    return true; return base.CanConvertTo (context, destinationType);
    } public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
    {
    if(destinationType == typeof(System.String) && value is MyCxpandableClass)
    {
    MyCxpandableClass so = (MyCxpandableClass)value; return "属性设置";
    }

    return base.ConvertTo (context, culture, value, destinationType);
    }
    }
      

  7.   

    不是FontInfo类本身,你看下TEXTBOX定义FontInfo属性的地方应该有编辑类属性描述的看一下对应的编辑类是如何定义的。
      

  8.   

    public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
    {
    if(destinationType == typeof(System.String) && value is MyCxpandableClass)
    {
    MyCxpandableClass so = (MyCxpandableClass)value; return "属性设置";
    }

    return base.ConvertTo (context, culture, value, destinationType);
    }################
    MyCxpandableClass so = (MyCxpandableClass)value;return "属性设置";
    ################
    上面这两句是为了做什么啊?
      

  9.   

    :) 知道了是做什么的了,谢谢 chinasdp()
      

  10.   

    查询PropertyGrid用法。
    查找自定义控件开发。
      

  11.   

    [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
    public class ImageStyle
    {
    public ImageStyle()
    {

    } private string name;
    private int age; public string Name
    {
    get {return name;}
    set {name = value;}
    } public int Age
    {
    get {return age;}
    set {age = value;}
    }
    }
      

  12.   

    哎,问题又出来了,请大家给看看
    http://community.csdn.net/Expert/topic/4339/4339217.xml?temp=.8715631