Is it possible to perform a specific action after the resize event (of the user control), for example when mouse button is released? I need to manually resize an inner control and doing it on every single firing of the event would be quite, hmm, inefficient...
-
There are better ways to do control layout. – leppie Jun 21 '10 at 08:44
-
I know and I wouldn't do this that way, but it's a little special case ;) – brovar Jun 21 '10 at 08:47
-
Anything wrong with the `Control.Resize` event? – leppie Jun 21 '10 at 08:50
-
3@leppie - the Resize happens a number of times during a user resizing a window. He wants an event that occurs when the user has finished resizing. – djdd87 Jun 21 '10 at 08:54
5 Answers
Just use the ResizeEnd
event:
private void Form1_ResizeEnd(object sender, EventArgs e)
{
// Your code here
}
From MSDN:
The ResizeEnd 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. For more information about the resizing operation.

- 67,346
- 27
- 156
- 195
-
Very tempting and I'd probably have already used it, but it's happening in the user control (I forgot to specify that, sorry) and I don't have access to the form's events. – brovar Jun 21 '10 at 09:08
-
@brovar: That's baloney! Every control has a `ParentForm` property. So in fact you have all that accessible! – leppie Jun 21 '10 at 09:09
-
@Why can you not just add a `ResizeMeNow()` method to the user control and call it on the Form's `ResizeEnd` event? – djdd87 Jun 21 '10 at 09:10
-
@brovar - or like leppie has said, you can just hook into UserControl.ParentForm.ResizeEnd+= ... etc. – djdd87 Jun 21 '10 at 09:11
-
Yes, I do have ParentForm, but it's not accessible after Handles and AddHandler is not something very welcomed in this application's code. (yep, VB.NET, not c#) – brovar Jun 21 '10 at 09:19
-
Hmm... but it seems that ResizeEnd event is not firing in case when form is maximized. (Layout event is fired, but it fires before contained controls are resized) – Prokurors May 14 '14 at 16:59
You can fake a local ResizeEnd like this:
public class Dummy:UserControl
{
private readonly Timer _tDelayedResize;
public Dummy()
{
this.Resize += this_Resize;
_tDelayedResize = new Timer();
_tDelayedResize.Interval = 5;
_tDelayedResize.Tick += this_ResizeEnd;
}
void this_Resize(object sender, EventArgs e)
{
_tDelayedResize.Stop();
_tDelayedResize.Start();
}
void this_ResizeEnd(object sender, EventArgs e)
{
_tDelayedResize.Stop();
//Do your ResizeEnd logic here
//...
}
}
The interval can be modified. The higher it is the more delay after the last resize event it will be.

- 16,600
- 12
- 59
- 58
-
I'm just looking at this code (I didn't run it)--but it seems to me that this will equate to a Resizing event and not a ResizeEnd event. – Jazimov Jan 19 '20 at 17:52
A simple solution is to override the OnResize in the form and prevent it calling the base method.
Call this base method at the start of the OnResizeEnd stage instead.
protected override void OnResize(EventArgs e)
{
// base.OnResize(e);
}
protected override void OnResizeEnd(EventArgs e)
{
base.OnResize(e);
base.OnResizeEnd(e);
}
Forms being maximised or restored can only be detected in the OnResize.
To accommodate this, you need to track the window state and allow the OnResize to go ahead when it changes:
private FormWindowState _LastWindowState;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
_LastWindowState = WindowState;
}
protected override void OnResize(EventArgs e)
{
if (WindowState != _LastWindowState)
{
base.OnResize(e);
_LastWindowState = WindowState;
}
}
protected override void OnResizeEnd(EventArgs e)
{
base.OnResize(e);
base.OnResizeEnd(e);
}
On another note, using code like this should be a last resort. Problems with controls resizing naturally would usually indicate bad design/coding.

- 21
- 2
Another option if you are using a control and not a form and would like to perform actions after the resize has been completed (user stopped resizing control):
private int resizeTimeout = 0;
private Task resizeTask;
public void OnResize()
{
resizeTimeout = 300; //Reset timeout
//Only resize on completion. This after resizeTimeout if no interaction.
if (resizeTask == null || resizeTask.IsCompleted)
{
resizeTask = Task.Run(async () =>
{
//Sleep until timeout has been reached
while (resizeTimeout > 0)
{
await Task.Delay(100);
resizeTimeout -= 100;
}
ResizeControl();
});
}
}
private void ResizeControl()
{
if (this.InvokeRequired)
{
//Call the same method in the context of the main UI thread.
this.Invoke((MethodInvoker)delegate { ResizeControl(); });
}
else
{
// Do resize actions here
}
}

- 1,611
- 18
- 28
-
1I don't even remember what the question was actually about, but wow! Thanks for answering! – brovar Oct 01 '21 at 14:12
Maybe you can use the SizeChanged Event. But i don´t know how often or when it´s called during resizing.

- 34,674
- 10
- 123
- 155