在设计时获取当前表单的所有控件 [英] Get all controls of the current form at design-time

查看:52
本文介绍了在设计时获取当前表单的所有控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对设计时的事情有疑问:

I have a question about design-time things:

我制作了一个具有链接"属性的组件.这些链接是控件.现在,我想制作一个UI对话框(用于在属性网格中编辑此属性).

I've made a component with an property "Links". Those links are Controls. Now I want to make a UI-Dialog (for editing this property in the property grid).

如何获取当前表格的所有控件?我认为该组件与它有连接,但是在哪里?我什么都找不到.

How can I get all controls of the current form? I think the component has an connection to it, but where? I can't find anything.

谢谢:)

推荐答案

这是非常简单的事情,我不知道执行此操作的.NET组件的任何示例.您可以在设计时使用Site属性进入表单,但是存在问题.很难处理的是用户删除控件,这些控件已经添加到控件集合中.除了必须为表单或用户控件使用自定义设计器之外,我不知道有什么好的触发器可以使您的收藏有效.

This is quite untrivial to do, I don't know of any examples of .NET components that do this. You can get to the form at design time with the Site property but there are problems. What's hard to deal with is the user deleting controls, ones that you have already added to your controls collection. I don't know of any good trigger to keep your collection valid, beyond also having to use a custom designer for the form or user control.

有一个更好的捕鼠器,例如,您可以看到它被HelpProvider和ErrorProvider组件使用.注意它们如何将属性添加到窗体上的所有其他控件.这是通过实现IExtenderProvider接口来完成的. MSDN库文章中有一个很好的例子

There's a better mousetrap for this, you see it being used by the HelpProvider and ErrorProvider components for example. Note how they add properties to all other controls on the form. This is done by implementing the IExtenderProvider interface. There's an excellent example of this in the MSDN library article.

这篇关于在设计时获取当前表单的所有控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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