I have following code:
for(int I=0;I<10;I++)
{
graphics.DrawImage(image, i*20,50);
invalidate();
}
But it redrawns just after the loop. Why?
EDIT: I am making simple movement and wants to update after each step.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because
Invalidatedoes not repaint immediately, it just tells that a repaint is needed. When the method is completed, and the program is idle again, the repaint will be performed.The quick and dirty solution is to add
Application.DoEvents()after theInvalidatecall, but I would suggest rewriting the logic to use a timer or something similar instead of using the loop to animate.