I've added a resize event to one of my widgets, which looks like this:
void glControl_Resize(object sender, EventArgs e) {
Is there a way I can get the old size of the widget (before resizing)? Maybe I can cast e
to something that will give me more info? Or should I just save it during that event?
Resize Event System. Windows. Forms Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here. Occurs when the control is resized. The following code example handles the Resize event of a Form.
The Resize event occurs when the control is resized, while the SizeChanged event occurs when the Size property changes. You could use either, as a resize will cause the Size property to change.
System. Windows. Forms Control. Size Changed Event System. Windows. Forms Occurs when the Size property value changes. The following code example demonstrates the SizeChanged event. An instance of a Button control has been provided that can be scaled both horizontally and vertically.
The resize event fires when the document view (window) has been resized. In some earlier browsers it was possible to register resize event handlers on any HTML element. It is still possible to set onresize attributes or use addEventListener () to set a handler on any element.
Yes, just tracking the old size in a class field is the simple solution. For example:
Size mOldSize;
private void glControl_Resize(object sender, EventArgs e) {
if (mOldSize != Size.Empty && mOldSize != glControl.Size) {
// do something...
}
mOldSize = glControl.Size;
}
By convention you should add an OnResizing
event, which fires just when it is about to change but hasn't changed, and then you fire the OnResize
after it has been resized. You would get the old value from your EventArg
in the OnResizing
event.
Edit:
Are you creating your own event or firing one of an included control?
If you are doing your own event, you can derive from EventArg
and make something like ResizeEventArg
that include the size of the thing you want.
I would use the ResizeEventArg
for both the Resize
and OnResizing
events, and still follow what I said earlier.
Or if you know which type of control it is, you could cast the Object sender
into the type and then read the property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With