在 Onload 方法中调用 base.Onload(e) 时,OnLoad 被调用
我有一个视图(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
感谢 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.