tags:

views:

103

answers:

2

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?

+2  A: 

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.

Francisco Noriega
I'm not creating my own event. And it doesn't have an `OnResizing` event? Nothing seems to have an `OnResizing` event? I see a `ResizeBegin` on my main form, but this is a `Tao.Platform.Windows.SimpleOpenGlControl` which doesn't seem to have either. Guess I'm snookered. Thanks anyway. Good for future reference.
Mark
+1  A: 

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;
}
Hans Passant
Works great, simple effective solution thanks for this
MikeG