Jack Jackson said:
On Wed, 9 Apr 2008 11:17:00 -0700, Morten Wennevik [C# MVP]
:
On Wed, 9 Apr 2008 00:05:01 -0700, Morten Wennevik [C# MVP]
:
There is indeed an override; OnSizeChanged, that should be used in this
case.
What's the point of the OnSizeChanged? All it does is raise the Resize event
and then call any delegates which have been wired to the SizeChanged event.
But OnResize also calls delegates that are wired to the Resize. So why
two...?
Actually, that is not all it does. You can override the OnSizeChanged
method to trap SizeChanged events fired elsewhere.
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
// Additional code needed to run when the size changes
}
I'm still not clear on this. Are there situations when the framework
fires Resize but not SizeChanged?
The framework won't ever fire 'Resize' only 'SizeChanged' but SizeChanged
will be fired when a control is resized. To detect a SizeChanged event you
typically subscribe to the SizeChanged event or override the OnSizeChanged
method (The reason for 'On' before the event name is due to limitations in
inheriting events, as only the base class can fire the actual event.
Inherited classes needs to use a method exposed by the base class).
I thought SizeChanged raised the Resize event?
If Resize is only raised from SizeChanged, why is there a Resize
event?
I still don't understand the purpose of Resize.
My apologies Jack, there is indeed a Resize event, and it is fired after
the SizeChanged event and it is indeed fire in reponse to some code running
in Control.OnSizeChanged.
The sequence when resizing a control is OnResizeBegin -> OnSizeChanged ->
OnResize -> OnSizeEnd
The documentation says that the Resize event is fired when a Control is
resized, whereas the SizeChanged event is fired when the Size property is
changed. It is a little more complicated than this as overriding
OnSizeChanged and NOT pass the event to base.OnSizeChanged() will prevent the
Resize event from firing, so handling SizeChanged instead of Resize to detect
size changes appears to be safer.