Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个类,我在其中传递了一个面板引用,然后在该面板中我需要绘制多个其他代表我的对象的面板。问题是,当我将动态单击事件绑定到这些面板时,我没有引用要在单击事件上弹出的表单。
这种结构的原因是我可以动态地重绘我的类并将某些事件重新附加到每个对象。
有没有办法在不将我的类逻辑移到程序集之外的情况下做到这一点,或者有没有办法将我的点击事件附加到一段代码逻辑到我的 WinForm 中的子程序?
如果您引用了 a 上的任何控件,Form则可以递归地向上导航该Parent属性,直到您点击Form. 只需测试父属性的类型是否可以分配给 type 的变量Form。
Form
Parent