简体   繁体   English

如何在Location和Font属性的设计时复制行为(举个例子)

[英]How to replicate the behavior on design time of Location and Font property (To give an example)

I want to set a property which contains other properties inside (Like font or Location Properties), I've done the following: 我想设置一个属性,其中包含其他属性(如字体或位置属性),我已经完成了以下操作:

class Example:DataGridView
{
    private PlusProperties X;

    public Example()
    {
        X = new PlusProperties();
        AdditionalProperties = X;

    }

    [ComVisibleAttribute(true)]
    [System.ComponentModel.Browsable(true), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)]
    [System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)]
    public PlusProperties AdditionalProperties
    {
        get { return X; }
        set
        {
            X = value;
        }
    }
}

public class PlusProperties
{
    private Color Pcolor = Color.DimGray;
    private Color Ccolor = Color.DimGray;

    public PlusProperties()
    {

    }

    [System.ComponentModel.Browsable(true), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)]
    public Color ParentColor
    {
        get { return Pcolor; }
        set
        {
            if (value != Pcolor)
            {
                Pcolor = value;
            }
        }
    }

    [System.ComponentModel.Browsable(true), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)]
    public Color ChildColor
    {
        get { return Ccolor; }
        set
        {
            if (value != Ccolor)
            {
                Ccolor = value;
            }
        }
    }

}

在此处输入图片说明 在此处输入图片说明

How can achieve the same behavior on design time (I mean show the properties of the class)? 如何在设计时实现相同的行为(我的意思是显示类的属性)?

Thanks in advance for your help. 在此先感谢您的帮助。

You'll want to create a class that inherits ExpandableObjectConverter and add a TypeConverter attribute to your class that uses it. 您将要创建一个继承ExpandableObjectConverter的类,并向使用它的类中添加TypeConverter属性。 See the following example here: https://msdn.microsoft.com/en-us/library/system.componentmodel.expandableobjectconverter(v=vs.110).aspx 请参见此处的以下示例: https : //msdn.microsoft.com/zh-cn/library/system.componentmodel.expandableobjectconverter(v=vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM