Winforms 组件的父级/所有者 [英] Parent/owner of a Winforms component

查看:23
本文介绍了Winforms 组件的父级/所有者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从嵌入在表单中的自定义 Winforms 组件,如何获取父/所有者控件?

From a custom Winforms component that is embedded in a form, how to I get the parent/owner control?

我有一个 IContainer 并且 Site 属性不为空,但我不知道如何到达真正的"父级.

I have an IContainer and the Site property is not null, but I have no idea how to get to the "real" parent.

(这是这个问题的后续,atm 我正在尝试向父母 VisibleChanged 添加一个处理程序,但这不是我第一次遇到这个问题)

(this is a followup to this question, atm I am trying to add a handler to the parents VisibleChanged, but that's not the first time I face this question)

推荐答案

不理想,但试试这个...

Not Ideal, but try this...

将用户控件更改为组件类(在代码编辑器中),构建解决方案并删除所有有错误的代码(与用户控件相关但在组件中不可用,因此调试器会抱怨)

Change the usercontrol to Component class (In the code editor), build the solution and remove all the code with errors (Related to usercontrols but not available in components so the debugger complains about it)

将用户控件改回用户控件类...

Change the usercontrol back to usercontrol class...

现在它可以识别名称和父属性,但将组件显示为不可见,因为它不再可设计.

Now it recognises the name and parent property but shows the component as non-visual as it is no longer designable.

这篇关于Winforms 组件的父级/所有者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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