|
| OnSizeChanged vs OnResize |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.framework.windowsforms.controls.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| J.Marsch |
What's the difference between OnSizeChanged and OnResize? I assume that there must be some kind of behaviorial difference, or there wouldn't be two sets of virtual + event to capture the same phenomena.
|
|
|
| |
|
| |
| |
| Patrick Steele [MVP] (VIP) |
In article <#Click here to reveal e-mail address>, Click here to reveal e-mail address says... [Original message clipped]
Resize: Occurs when the control is resized.
SizeChanged: Occurs when the Size property value changes.
My guess is that if I resize with the mouse, I'll get both events. If I change the Size property, I'll only get the SizeChanged event.
-- Patrick Steele Microsoft .NET MVP http://weblogs.asp.net/psteele
|
|
|
| |
|
|
| |
| |
| J.Marsch |
No, I'm afraid that doesn't pan out.
If I capture both the Size and Resize events on a form, I find that both events fire at runtime, regardless of whether I use the mouse or code to change the size. Both events fire continuously during the mouse resize operation.
Of course, your statement may be technically true, but using the mouse resize a form still results in the Size property changing.
Here's the code that I used: (form with it's SizeChanged and Resize events hooked, and a button that, when clicked, directly alters the Size property. Same behavior either way).
private void Form1_SizeChanged(object sender, System.EventArgs e) { System.Diagnostics.Debug.WriteLine("SizeChanged"); }
private void Form1_Resize(object sender, System.EventArgs e) { System.Diagnostics.Debug.WriteLine("Resize"); }
private void button1_Click(object sender, System.EventArgs e) { System.Drawing.Size size = this.Size; size.Height += 5; size.Width += 5; this.Size = size; }
"Patrick Steele [MVP]" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Kevin Westhead |
"J.Marsch" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
<snip>
It looks like you will always get both since OnResize is called from OnSizeChanged. I'd recommend using ILDASM (part of the fx SDK) or preferrably Reflector (http://www.aisto.com/roeder/dotnet/) to help you inspect the internals of the fx assemblies. The following was taken from Reflector:
protected virtual void OnSizeChanged(EventArgs e) { EventHandler handler1; this.OnResize(EventArgs.Empty);
if (this.CanRaiseEvents) { handler1 = (base.Events[Control.EventSize] as EventHandler);
if (handler1 != null) handler1.Invoke(this, e);
}
}
-- Kevin Westhead
|
|
|
| |
|
| |
| |
| J.Marsch |
Thanks, Kevin.
I have now looked at both methods in Reflector.
So, it looks as though I can use either one, but I'd still love to know why there are two. I wonder if there is some important nuance between the two. If there is, it looks as though it would only come into play when overriding the protected OnSizeChanged method, because the events themselves get fired one after the other. Weird.
Anyone know exactly why one might need this degree of control over the resize operation?
"Kevin Westhead" <kevinw@NOSPAM.i2DOTcoDOTuk> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
| |
| |
| Kevin Westhead |
"J.Marsch" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... > So, it looks as though I can use either one, but I'd still love to know why > there are two. I wonder if there is some important nuance between the two. > If there is, it looks as though it would only come into play when overriding > the protected OnSizeChanged method, because the events themselves get fired > one after the other. Weird.
It could be down to usability rather than a technical reason. The Resize event is no doubt familiar to VB6 developers whereas having a SizeChanged event is consistent with .NET design guidelines, namely that if a property value can be changed from code and from the GUI then a property-changed event should be considered.
-- Kevin Westhead
|
|
|
| |
|
|
| |
|
| |
| Ying-Shen Yu[MSFT] (VIP) |
Hi all,
I'm trying to find someone to answer this question, Thanks for your understanding!
Best regards,
Ying-Shen Yu [MSFT] Microsoft Online Partner Support Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights. This mail should not be replied directly, "online" should be removed before sending.
|
|
|
| |
|
|
| |
| |
| Ying-Shen Yu[MSFT] (VIP) |
Hi all,
Sorry for the long delay, I got the reply from the product team, Simple answer: From a user's point of view, they're the same thing. OnResize will be called whenever OnSizeChanged is called. The reason we have both is that OnSizeChanged is used for databinding and we had OnResize first. The user can override either one and see the same behavior.
Please reply this thread if you have anything unclear about it. Thanks!
Best regards,
Ying-Shen Yu [MSFT] Microsoft Online Partner Support Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights. This mail should not be replied directly, "online" should be removed before sending.
|
|
|
| |
|
|
| |
| | |
| |
| J.Marsch |
Ying-Shen:
Thank you for investigating this, even though it's not a problem, I'm glad to know why we see the two events. Also, I'm sorry for the delayed response -- I was on vacation last week.
-- Jeremy
""Ying-Shen Yu[MSFT]"" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|