开发者

.NET Resize Event: Get old size?

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 somethi开发者_开发百科ng that will give me more info? Or should I just save it during that event?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜