0

I'm trying to slide a control to the right when I move the cursor on that control and slide back when the cursor is out.

Since the form contains many control with the same animation, I've decided to let those control slide on different threads. The problem is, when I create a thread and use Control.Invoke() to change the location of the control, the main UI freezes until the animation is completed.

What am I doing wrong? Or is there any way to work around?

Edit: Also used Control.BeginInvoke(). The result is the same.

Stanley
  • 59
  • 6
  • tried beginInvoke() ? – inquisitive Jun 08 '13 at 09:46
  • Yes. Both will freeze the main UI. – Stanley Jun 08 '13 at 10:22
  • You are calling Begin/Invoke() too often, flooding the UI thread with invoke requests. Which makes it stop painting, a low priority task. Using a worker thread makes it slower, not better. Do favor the built-in support for animation in Windows, check [this answer](http://stackoverflow.com/a/6103677/17034). – Hans Passant Jun 08 '13 at 12:04

1 Answers1

0

That happens when you try to move the control faster than UI thread can handle. The below library is a good example of how to do animations with a SINGLE global FRAME-LIMITED timer for all animations.

WinForm Animation Library [.Net3.5+]

A simple library for animating controls/values in .Net WinForm (.Net 3.5 and later). Key frame (Path) based and fully customizable.

https://falahati.github.io/WinFormAnimation/

new Animator2D(
        new Path2D(c_control.Location.X, c_control.Location.Y, c_control.Location.X + 100, c_control.Location.Y, 250))
    .Play(c_control, Animator2D.KnownProperties.Location);

This moves the c_control control 100 pixels to the right in 250ms.

Soroush Falahati
  • 2,196
  • 1
  • 27
  • 38