设计时编辑器支持自定义控件 [英] Design Time Editors support for Custom control

查看:81
本文介绍了设计时编辑器支持自定义控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,

我想提供一个选项,在设计时自定义自定义控件,着色功能。我能够添加和显示设计器时间属性编辑器,但它的值不是序列化的。请在下面找到我的customcontrol源代码。 

I would like to provide an option to customize the custom control, coloring function in design time. I am able to add and display designer time property editor, but its value is not serialized. Please find my customcontrol source code in below. 

 public class ColorDialog : Control
    {
        public ColorDialog()
        {

        }

        private List<ColorTable> m_ColorTable = new List<ColorTable>();
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        [EditorAttribute(typeof(System.ComponentModel.Design.CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
        public List<ColorTable> ColorTable
        {
            get { return m_ColorTable; }
            set { m_ColorTable = value; }
        }
        private bool ShouldSerializeColorTable()
        {
            return true;
        }
    }

    [Serializable]
    public class ColorTable
    {
        private Color m_HoverColor = Color.Red;

        public Color HoverColor
        {
            get { return m_HoverColor; }
            set { m_HoverColor = value; }
        }

        public bool ShouldSerializeHoverColor()
        {
            return m_HoverColor != Color.Red;
        }

        private Color m_SelectionColor = Color.Red;

        public Color SelectionColor
        {
            get { return m_SelectionColor; }
            set { m_SelectionColor = value; }
        }

        public bool ShouldSerializeSelectionColor()
        {
            return m_SelectionColor != Color.Red;
        }
    }

显示设计时间编辑器。 

Design Time Editor is displayed. 

但该值未在序列化中表单设计器文件。请参阅下面的实际结果。 

private void InitializeComponent()
        {
	    this.colorDialog1 = new ColorTableCustomization.ColorDialog();
            this.colorDialog1.ColorTable.Add(((ColorTableCustomization.ColorTable)(resources.GetObject("colorDialog1.ColorTable"))));
        }


我的期望

My Expectation

            ColorTable colorTable = new ColorTable();
            this.colorDialog1 = new ColorTableCustomization.ColorDialog();
            this.SuspendLayout();
            // 
            // colorDialog1
            // 
            colorTable.HoverColor = Color.DarkGray;
            colorTable.SelectionColor = Color.Yellow;
            this.colorDialog1.ColorTable.Add(colorTable);


请指导我实现此目标。

Please guide me on achieving this.

MSDN ALERTS

MSDN ALERTS

推荐答案

嗨Ravindran S,

Hi Ravindran S,

我认为生成像动态实例化这样的设计代码是不可能的,当你在设计视图中添加它时,集合已经存储在位置变量资源(From.resx)中。

I think it is impossible to generate the design code like dynamic instantiation, the collection has been stored in the location variable resources(From.resx) when you add it at design view.

问候,

月光


这篇关于设计时编辑器支持自定义控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆