将现有项添加到集合编辑器 [英] Adding existing items to collection editor

查看:178
本文介绍了将现有项添加到集合编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我,我创建了一个包含控件集合的组件作为属性:

I, I've created a component with a collection of controls as property:

<pre lang="C#">[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public List<Component> ControlsToNotTranslate





然后我创建了一个UserControl,为它添加了一些控件:按钮和标签。

现在我想通过类似于ConnectionEditor的工具将这些按钮和标签添加到我的组件集合中,但是当我尝试在Visual Studio Designer中向集合中添加项目时,它会打开集合编辑器并且不会向我提供添加已创建的按钮和标签。



如何实现这一目标?



注意



通常我的控件集合不会包含父UserControl中的所有控件,但只包含少量控件,所以我会优先考虑将集合初始化为父UserControl中的所有控件。





谢谢



Matteo



Then I've created an UserControl, added some controls to it: buttons and labels.
Now I want to add this buttons and labels to the collection of my component via a ConnectionEditor like tool, but when I try to add items to the collection in the Visual Studio Designer, it opens the collection editor and does not give me the chanche to add the already created buttons and labels.

How can I achieve this?

Note

Usually my collection of controls won't contain all controls in the parent UserControl, but only a small amount of them, so I would prefere not to initialize the collection to all controls in the parent UserControl.


Thanks

Matteo

推荐答案

请查看这是否对您有所帮助,请参阅控件中的TargetControls属性form1你可以选择相同类型的控件,显示所有控件只是为了更改控件代码,在哪里是ExampleControl你改为Control。



链接到演示: https://1drv.ms/u/s!AmP2eCNNws8S9AOkUoWu3Iejj6Q8
Please see if this helps you in some way, see that in the "TargetControls" property of the control that is in form1 you can select the controls of the same type, to appear all the controls is just to change the control code, where is ExampleControl you changes to Control.

Link to demo: https://1drv.ms/u/s!AmP2eCNNws8S9AOkUoWu3Iejj6Q8


这篇关于将现有项添加到集合编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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