用户控件包含子控件,设计模式下编辑子控件 [英] User control containing child control, design mode edit child control

查看:103
本文介绍了用户控件包含子控件,设计模式下编辑子控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控件,在该控件中还有其他控件的集合(有点像选项卡控件-但不是选项卡控件)。

I have a control, within that control there is a collection of other controls (a bit like a tab control - but not a tab control).

所以我让我控制表格。我可以使用自定义集合设计器表单添加新的子控件,没问题。

So I have my control on a form. I can add new child controls using a custom collection designer form, no problem.

我希望能够以设计方式从表单向子控件添加控件视图。目前,如果我选择子控件并放下一个复选框,则该复选框将添加到父控件而不是子控件中,然后位于所有子控件的顶部。

I would like to be able to add controls to the child control in design mode from the form view. At present if I select the child control and drop say, a checkbox, the checkbox gets added to the parent control not the child control and then sits over the top of all child controls.

如何使放置在子控件上的控件实际上添加到子控件中,而不是在设计模式下是父控件?它是需要添加到某些东西的属性吗?我是否必须在其中添加一些自定义代码以捕获要添加的控件?

How do I make controls that have been dropped over the child control actually get added to the child control and not it's parent in design mode? Is it an attribute that needs adding to something? Do I have to add some custom code in there to trap the control being added?

推荐答案

首先要使内部控件设计者能够执行操作就像父控件一样:

First enable the inner control designer to behave like a parent control:

[Designer(typeof(ParentControlDesigner))]
public partial class InnerControl : UserControl

然后通过为外部控件创建新的控件设计器,在内部控件中托管内部控件时启用设计模式:

Then enable design mode for inner control when it's hosted in outer control, by creating a new control designer for outer control:

[Designer(typeof(OuterControlDesigner))]
public partial class OuterControl : UserControl
{
    public OuterControl()
    {
        InitializeComponent();
    }
    public InnerControl InnerControl { get { return innerControl1; } }
}

public class OuterControlDesigner:ControlDesigner
{
    public override void Initialize(IComponent component)
    {
        base.Initialize(component);
        this.EnableDesignMode(((OuterControl)this.Control).InnerControl, "InnerControl");
    }
}

这篇关于用户控件包含子控件,设计模式下编辑子控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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