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...
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With