WinForms - action after resize event

2019-06-15 05:52发布

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...

3条回答
唯我独甜
2楼-- · 2019-06-15 06:41

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.

查看更多
ら.Afraid
3楼-- · 2019-06-15 06:42

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.

查看更多
地球回转人心会变
4楼-- · 2019-06-15 06:43

Maybe you can use the SizeChanged Event. But i don´t know how often or when it´s called during resizing.

查看更多
登录 后发表回答