1

I have created a usercontrol which has transparent background. I use this usercontrol on windows form and do some animation stuff on control when a button is clicked. myctrl is usercontrol created in windows form. Below is code :

private void button1_Click(object sender, EventArgs e)
{
            Point p1 = new Point(myctrl.Location.X, myctrl.Location.Y);

            for (int i = 0; i < 100; i++)
            {
                myctrl.Location = new Point(p1.X + i, p1.Y + i);

                myctrl.Update();
                pictureBox1.Update();
                i++;
                Thread.Sleep(100);
            }
}

Problem : Once loop starts usercontrol is not visible and when loop ends control is visible. Also, I'm placing the control on picturebox which is placed on winforms.

1 Answers1

1

Perhaps you have to use Refresh instead of Update.

Or you may completely change how you do it once you read about AnimateWindow.

Edit

I must be blind to not notice a clear ussue with your animation. The point is, you doing it at once (with naive Thread.Sleep). And while you doing it, repainting is blocked (even if you call Refresh you will not see result). So yes, for a duration of animation there will be nothing visible.

What you have to do is to split animation (by using Timer more likely) into frames and display only one frame at once.

Community
  • 1
  • 1
Sinatr
  • 20,892
  • 15
  • 90
  • 319