   Windows paint events
  Hey,I have a small application written in C# which has a PictureBox in it. The picture box has an image as well as a set of lines that I draw myself on top of the image. But, I am having a problem with the lines flickering a lot and not redrawing if I move an other window over them. The actual image is being redrawed fine, so I am wondering if there is an update event that I have to registered to for my own lines. The only event that I do drawing in is the Paint event, but as I said, that causes a lot of flickering for the lines. What am I missing here?Thanks.   
  The common way for Windows controls to be drawn is two steps:First the background, then the paint call.For your use try setting double buffering to true (or set the control style Controlstyles.AllPaintingInWmPaint)   ;  Thank, but I couldnt get that to work. My picturebox does not have a Setstyle() function, so I tried setting it for the window it is in, but that did not change anything.Here is my render function that is called for the Paint event:private void render(){    DrawWindow.SuspendLayout();// Was hoping that this would pause the redraw    Graphics g = DrawWindow.CreateGraphics();    g.Clear(Color.Lime);    g.DrawImage(DrawWindow.Image,   new Rectangle(0, 0, DrawWindow.Right - vScrollBar1.Width, DrawWindow.Bottom - hScrollBar1.Height),   new Rectangle(hScrollBar1.Value, vScrollBar1.Value, DrawWindow.Right - vScrollBar1.Width, DrawWindow.Bottom - hScrollBar1.Height),   GraphicsUnit.Pixel);    for (int i = 0; i < m_rectangleList.Count; i++)    {   Brush brush = Brushes.Black;   Point p0 = m_rectangleList.Value.m_topLeft;   Point p1 = m_rectangleList.Value.m_bottomRight;   renderRectangle(p0, p1, m_rectLineWidth, brush, g);}    DrawWindow.ResumeLayout();}private void renderRectangle(Point topLeft, Point bottomRight, int size, Brush b, Graphics g){    topLeft.X -= hScrollBar1.Value;    bottomRight.X -= hScrollBar1.Value;    topLeft.Y -= vScrollBar1.Value;    bottomRight.Y -= vScrollBar1.Value;    g.DrawLine(new Pen(b, size), new Point(topLeft.X, topLeft.Y), new Point(bottomRight.X, topLeft.Y));    g.DrawLine(new Pen(b, size), new Point(bottomRight.X, topLeft.Y), new Point(bottomRight.X, bottomRight.Y));    g.DrawLine(new Pen(b, size), new Point(topLeft.X, topLeft.Y), new Point(topLeft.X, bottomRight.Y));    g.DrawLine(new Pen(b, size), new Point(topLeft.X, bottomRight.Y), new Point(bottomRight.X, bottomRight.Y));};  It's a bit weird: You need to derive a class from PictureBox and in the constructor call the Setstyle method.   ;  I made a wrapper for my c++ render code it had same problem of flickering but only sometimes. I used to getaround 200-300 fps.But later i added a background thread and inserted my render code in that it boosted my fps to 1500fps and flickering problem was gone completely.You can also try by inseting you draw code in a background thread.   