Solutions | flashing | problems
Ever since MiG's Guy recommended C # to me, I've strayed from the Java camp. Recently in writing tools, suddenly found a commonplace flicker problem, to know this problem in the Java swing as long as the DoubleBuffer set to true is basically not going to happen, but in C # but how can also be uncertain, even double buffers have problems, GDI + It's not so fragile.
Once again I was teased by Microsoft's flower head, helpless had to embark on a long search road, also do not know how many posts searched, find how much information, basically are reactive and return, more exasperating is some information on the internet also cheat, I tried to basically do not, the flash of the same flash Huan. Some methods, like dirty matrices, want to invalide partially update regions, I suspect him trouble, fortunately I found an article, said the principle of flicker, although I used to think that understanding the principle of flicker, such as what the refresh cycle, memory and so on, but I still have the patience to see again, the harvest is quite abundant, It seems that Confucius's warm knowledge of the new quite reasonable!
So I changed the code according to the principle, did not expect to really let me to solve. The C # control flashes because refresh Qingcheng the entire control to the background color, and then draws the image, even if all the images to be drawn are drawn to the buffer and then render to the control, because the color of the screen is equivalent to a blank frame in the middle, Flashes can also occur when the refresh is too fast.
My practice is to:
1. Each frame control creates a graphics, remembering that it must be creategraphics instead of the parameter e of the paint function.
2. Draws the image to be drawn to the buffer, the buffer size is the control size.
3. Refresh Time Call Invalidate (new Rectangle (0, 0, 1, 1));
4. Draw the buffer in the paint function, fix it!
Haha, I believe everyone will understand, Invalidate (new Rectangle (0, 0, 1, 1)), the equivalent of calling the paint function, but not redrawing the control, so that the middle of the blank frame is gone, flashing of course disappeared!
The principle is very important AH very important!