设计时编辑器支持自定义控件

编程入门 行业动态 更新时间:2024-10-12 03:20:17
本文介绍了设计时编辑器支持自定义控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨专家,

我想提供一个选项,在设计时自定义自定义控件,着色功能。我能够添加和显示设计器时间属性编辑器,但它的值不是序列化的。请在下面找到我的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.

问候,

月光

更多推荐

设计时编辑器支持自定义控件

本文发布于:2023-11-07 19:07:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567178.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   编辑器   控件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!