Layout event and designer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

All -
I have a custom control - in which when a property value changes, i call
"PerformLayout" method (becoz my internal layout calculations have changed).
I also override "OnLayout" to do the actual layout calculations.

When the control is used from "VS Designer", form.designer.cs generates
following code:
customControl.SuspendLayout();
customControl.SomeProperty = someValue;
// < the above propertychange will call PerformLayout internally>
customControl.ResumeLayout(false); // Note the "false"

The problem is that since SuspendLayout was called, PerformLayout does a
"NoOP" i guess and the overridden OnLayout is *never* called (confirmed thro'
debugger).

Albeit changing ResumeLayout(false) to ResumeLayout(true) makes everything
work fine.

My question is -
(a) Why z ResumeLayout(false) called by the designer instead of true- not
allowing pending layout events to be processed?

(b) Is my technique of overriding "OnLayout" event to perform layout
calculations and using PerformLayout to force new layout incorrect?
If so what is the correct way to do this?

I am using VS 2005 - C#.

Regardz
Grafix.
 
Grafix wrote:
....
My question is -
(a) Why z ResumeLayout(false) called by the designer instead of true- not
allowing pending layout events to be processed?

My guess is, this is to overcome C# somewhat questionable approach
to inheritance. If you are in the constructor of the base class, you are
already of the type of the inheritor, not the base. This means that
if layout is allowed, and the inheritor overrides the OnLayout method,
the method will be called on the inheritor, who obviously does not exist
at this point yet.
(b) Is my technique of overriding "OnLayout" event to perform layout
calculations and using PerformLayout to force new layout incorrect?
If so what is the correct way to do this?

I would simply set that property outside the generated code, by hand,
e.g. in OnCreateControl.
 
Back
Top