views:

90

answers:

2

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.

+2  A: 

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 Passant
A: 

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.

Bilel Boughanmi