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...
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
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.
回答3:
Maybe you can use the SizeChanged Event. But i don´t know how often or when it´s called during resizing.