Is there a done resizing event ?

G

Guest

I'm writing a new control derived from UserControl.
I need to get an event when the control is done resizing.

I tried the Resize, SizeChanged, Move and the Layout events and I also tried
to override them. But they all invoked when the control is in the middle of
the resizing process.

I'm not using breakpoints, I'm using trace to see which one is invoked and
when.

Is there an event that simply tells me when the resizing is done ?
 
G

Guest

It looks like a good idea, but it's may be good for Forms, but I need it for
the control that I'm writing.
I'll explain:
The control that I'm writing can no be resized separately, it's being
resized by resizing its parent Form.
(The Form is setting my control Dock = None, Anchor = Top,Left,Right).
So when the user done resizing the Form, the MouseUp is in the Form context
and of the control.
I tried to set Parent.MouseUp (where Parent is the Form) event, but it is
not being fired.

So I'll be very happy to hear any more Ideas.


----------
Thanks
Sharon
--
Thanks
Sharon


Abubakar said:
Hi,
In case the window is being resized with a mouse, you can treat a mouseup
event to be end of resizing.
I hope that helps u.

-Ab.
http://joehacker.blogspot.com
 
A

Abubakar

The following code works in visual studio 2k5:

private void UserControl1_Load(object sender, EventArgs e)
{
((Form)this.Parent).ResizeEnd += new EventHandler(UserControl1_ResizeEnd);
}
void UserControl1_ResizeEnd(object sender, EventArgs e)
{
MessageBox.Show("Resize end");
}

I hope that helps.

-Ab.
http://joehacker.blogspot.com

Sharon said:
It looks like a good idea, but it's may be good for Forms, but I need it for
the control that I'm writing.
I'll explain:
The control that I'm writing can no be resized separately, it's being
resized by resizing its parent Form.
(The Form is setting my control Dock = None, Anchor = Top,Left,Right).
So when the user done resizing the Form, the MouseUp is in the Form context
and of the control.
I tried to set Parent.MouseUp (where Parent is the Form) event, but it is
not being fired.

So I'll be very happy to hear any more Ideas.
 
G

Guest

That is very good, But I'm using the VS 2003 that does not have the
ResizedEnd event.
 
J

Jeffrey Tan[MSFT]

Hi Sharon,

Thanks for your feedback.

First, you should determine if ResizeEnd event meets your need. This event
is raised when the user finishes resizing a form, typically by dragging one
of the borders or the sizing grip located on the lower-right corner of the
form, and then releasing it. It is also generated after the user moves a
form, typically by clicking and dragging on the caption bar.

So for the second scenario, I do not think it meet your need. However, I
think we can distinguish these 2 conditions with comparing the new control
size with the original control size.(This requires to store the original
control size in a private filed/property)

Ok, I assume that you need this event in .Net1.1. Let's do some
customization to achieve this:
Form.ResizeEnd event leverages win32 WM_EXITSIZEMOVE message, so in
.Net1.1, we can override Form's WndProc and create a public ResizeEnd
event, trigger this event in WM_EXITSIZEMOVE message, like below:

public event EventHandler ResizeEnd;
private int WM_EXITSIZEMOVE=0x232;
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_EXITSIZEMOVE)
{
if(ResizeEnd!=null)
{
this.ResizeEnd(this, new EventArgs());
}
}
base.WndProc (ref m);
}

In usercontrol, we can just listen to this event:
//I write code to disable this code from running in designmode.
private void UserControl1_Load(object sender, System.EventArgs e)
{
if(!this.DesignMode)
{
((Form1)this.Parent).ResizeEnd += new
EventHandler(UserControl1_ResizeEnd);
}
else
{
MessageBox.Show("design time");
}
}

private void UserControl1_ResizeEnd(object sender, EventArgs e)
{
MessageBox.Show("Resize end");
}

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Thanks Jeffrey,
But I'm only writing the control that will be used in Forms that I have no
control over them.

As I understand your suggestion; the event is fired by the Form.
So you see, it's very good for the Form developer, but not for the control
developer.

I found some discussion that suggest to use the Application.Idle event.
So on the regular OnResize I'm only marking a flag that indicate that a
resizing operation is in progress, and the event handler that is register for
the Application.Idle event is doing the resizing (as if ResizeEnd is fired)
when the flag is marked.
It seems to be working, but I'm not so sure it will work at any scenario.

What do you think?
 
J

Jeffrey Tan[MSFT]

Hi SharonG,

First, I think I have showed you the code how to register the form's
ResizeEnd event in UserControl, yes? So we should can do this in the
control development, not just the Form level. Do you have any concern on
this way?

Second, I am not sure what is your definition of resizing end. Based on my
experience, the Resize event should occurs at the end of the resizing
operation, yes? Please feel free to tell me concern about this.

Third, the Application.Idle should can get this done. Because this event
occurs when the application finishes processing and is about to enter the
idle state. So the Resizing operation should have been finished.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
B

Bruce Wood

Jeffrey,

Wouldn't it be better to subscribe to the parent form's Resize_End
event in a ParentChanged event handler, rather than in a Load event
handler?
 
G

Guest

Yes, the code you showed me is perfect. But I prefer a solution that won't
involve the user of the control.

My definition of 'resizing end' is the mouse up when the user is done
pooling the Form corner.
So I think that our detentions are the same.

I'm glad to hear that the Application.Idle event usage is a good solution.
As you can see it does not need any involvement by the user of my control.
 
G

Guest

Yes, it would be better to register to the ResizeEnd event of the parent
Form. But this event is only exist in VS 2005 and not in VS2003.
The Solution that Jeffrey has suggested is for VS2003.
 
J

Jeffrey Tan[MSFT]

Oh, yes, it;'s better can use the control without requiring doing extra
work in Form class. So the solution you found should be better.

If you have any further concern, please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top