I’m painting an image with e.Graphics.DrawImage in the Form_Paint() event. I use a Timer to refresh the form. The problem is that the animation blinks. It seems that it is taking too long to update e. I have 2 PictureBox inside the Form.
Ideas?
UPDATE:
public Bitmap Paint(int state, Graphics g)
{
this.state = state;
Bitmap temp;
Graphics tempGraphics;
temp = new Bitmap(45, 47, g);
tempGraphics = Graphics.FromImage(temp);
switch (state)
{
case 0:
tempGraphics.DrawImageUnscaled(img, x, y);
break;
case 1:
tempGraphics.DrawImageUnscaled(img, x, y - 42);
break;
}
}
This prepares the sprite before adding it to the form.
I solved the problem by avoiding doing any animation on the form itself. If you add controls to a form and then you animate the parent, you over-do the UI thread. The best solution was keeping all the animations in pictureboxes.
So: you either animate directly with
g.DrawImage()or you stick to usingPictureBox.