在 Onload 方法中调用 base.Onload(e) 时,OnLoad 被调用

发布于 2024-09-02 22:45:09 字数 157 浏览 2 评论 0原文

我有一个视图(userControl),我正在重写它的 OnLoad 和 OnLayout 方法。当视图关闭时,将执行 OnLayout 方法,并且对 base.OnLayout(e) 的调用会触发 OnLoad 方法。

是什么导致 OnLoad 被调用以及如何避免这种行为? 问候。

I have a view (userControl) and I am overriding it's OnLoad and OnLayout methods . When view is closed the OnLayout method is executed and the call to base.OnLayout(e) fire the OnLoad method.

What is causing the OnLoad to be called and how can I avoid this behavior?
Regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慕烟庭风 2024-09-09 22:45:09

OnLoad 被再次调用,因为 base.OnLayout() 使用将重新创建窗口的属性。这不好,你肯定需要解决这个问题。您需要找出为什么在释放控件时调用 OnLayout。在 OnLayout 覆盖上设置断点并检查调用堆栈。如果您无法理解它,请将其发布在您的问题中。

OnLoad is called again because base.OnLayout() uses properties that will recreate the window. That's not good, you'll definitely need to fix that. You'll need to find out why OnLayout is getting called when the control is being disposed. Set a breakpoint on your OnLayout override and check out the call stack. Post it in your question if you can't make sense of it.

三人与歌 2024-09-09 22:45:09

感谢 Hans 的回复,

由于调用了 dispose,Windows 窗体布局似乎正在调用控件上的布局。无论如何,作为一种解决方法,我将调用 base.OnLayout() 与 SuspendLayout() 和 ResumeLayout 围绕在一起。

问候。

Thanx Hans for your reply,

It seems that Windows Forms layout is calling layout on controls due to dispose being called. anyway, as a work around I am surrounding the call base.OnLayout() with SuspendLayout() and ResumeLayout.

Regards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文