Graphics g = drawPanel.CreateGraphics();
Using CreateGraphics () and enabling double buffering is the worst possible combination. CreateGraphics () provides a Graphics object that draws directly on the screen. Double buffering sets a Graphics object that draws a bitmap image, a buffer used in double buffering. It then displays the bitmap on the screen at the end of the drawing cycle.
So what happens in your code is that you draw the screen directly, something that you can hardly see but see if it is slow enough. Then right after this buffer, which you never draw, is drawn. What wipes what you painted before. The net effect is a heavy flicker with your image visible only for a few milliseconds.
Using CreateGraphics () was a mistake. You always want to render through the e.Graphics object that you get from the Paint event so that you display the buffer. Pass this Graphics object to your drawMonomers () method. In this way:
public void drawMonomers(Graphics g, Point location, string state) {
In general, CreateGraphics () has very limited utility. You only ever use it when you want to paint right on the screen, and you can afford everything you painted to disappear. This is usually useful only in the form of a program in which the visualization cycle is constantly working, creating a new output with a high speed, for example, 20+ frames per second. Like a video game.
source share