I am trying to implement a simple animation when I pick an image in c#, using winforms. The objective is that when the user touches one of the images that are reduced, on mouse-down, it resizes (grows up) and passes a bit of their original size(the original size is bigger than the start size), and the next instant it comes back to the original size.
The code I'm trying to implement is the following:
// - Grows up the control to a bigger size than the original one
while ((sender as Peça).Width < (sender as Peça).imagem.Width) { (sender as Peça).Width = (int)((sender as Peça).Width * 1.8);
(sender as Peça).Height = (int)((sender as Peça).Height * 1.8);
(sender as Peça).setSize(new Size((sender as Peça).Width, (sender as Peça).Height));
Application.DoEvents();
}
// - Return the size of the control to the original one
if ((sender as Peça).Width > (sender as Peça).imagem.Width) { (sender as Peça).Width = (sender as Peça).imagem.Width;
(sender as Peça).Height = (sender as Peça).imagem.Height;
(sender as Peça).setSize(new Size((sender as Peça).Width, (sender as Peça).Height));
}
I am not getting the results I wanted. The animation is not smooth, and for that reason I think I am not doing it correctly.
I know that winforms is not the best for this, but I have to use it. Is there any animation library for winforms?