none
Regarding flickering along edges while scrollign a panel in C# and adding and deleting graphics to the panel RRS feed

  • Question

  • Hi,

         I am trying to create a GUI  where I am supposed to open an image and mark certain regions. Until now I have used split container but I experienced some flickering when I scroll the image. I am not sure if it occurs in other instances when I draw regions and delete them .But right now my concern is the flickering  along the edges as I scroll the image.

     

    2) Then I thought including a picturebox inside splitcontainer panel would be good. Luckily this removed the flicker while scrolling. The issue I had with picture box was that. If I deleted the graphic such as a polygon I had drawn earlier after which I called a method which redraws all the other polygons. But the other polygons are not visible unless I click on the scroll bar. Then I tried double buffering where in the event of deleting a polygon I drew the graphics onto the bitmap and loaded that image in "picturebox.Image = mybitmap". this worked perfect but I am not sure if I can use markers and move the polygons if I draw on to bitmap.

     

    3) My last resort was to remove all containers(toolstrip container, splitcontainer) and just have two panels and menustrip on the form and draw on one of the panels. But I hit the problem of flickering along the edges as I scroll. I tried the class example you had mentioned. It didnt seem to work in my case.

    Just to give a gist of my code.

    I call a method DrawImage() inside the paint event for panel.

    void DrawImage()
            {
                if (gr != null)
                {
                    gr.Dispose();
                    //redBrush.Dispose();
                    //blackPen.Dispose();
                }
                gr = this.panel2.CreateGraphics();
                this.panel2.AutoScrollMinSize = new Size(myBitmap.Width, myBitmap.Height);
               
                gr.DrawImage(myBitmap, new RectangleF(this.panel2.AutoScrollPosition.X,   this.panel2.AutoScrollPosition.Y, myBitmap.Width, myBitmap.Height));

     

            }

     

    Thank you.

    Friday, July 16, 2010 3:30 PM

Answers

  • Hi,

        I Have found the solution for flickerign along the edges of the panel. I created a new class derived from Panel and added it to the form for painting.

     

    class DoubleBufferPanel:Panel
        {
            protected override CreateParams CreateParams
            {
                get
                {
                    CreateParams cp = base.CreateParams;
                    cp.ExStyle |= 0x20;
                    return cp;
                }
            }

            protected override void OnPaintBackground(PaintEventArgs e)
            {
                //Dont paint here
            }

        }

     

     

    and added the following code in the form1.designer.cs

    this.panel1 = new DoubleBufferPanel();

    private DoubleBufferPanel panel1;

     

    instead of using the following code in designer code

    this.panel1 = new System.Windows.Forms.Panel();

    private System.Windows.Forms.Panel panel1;

     

     

    But I still could not resolve repainting of the lines when I scroll the image. When I scroll the image the lines which are drawn on the image are redrawn which results in the lines flickering or blinking like. That is the lines drawn dont look as though they are painted permanently and fade away constantly until the scrolling is stopped.

     I hope this would help some other users :)

     

    Thank you

    • Marked as answer by SamSund Thursday, July 29, 2010 2:54 PM
    Thursday, July 29, 2010 2:53 PM

All replies

  • Hi,

        I Have found the solution for flickerign along the edges of the panel. I created a new class derived from Panel and added it to the form for painting.

     

    class DoubleBufferPanel:Panel
        {
            protected override CreateParams CreateParams
            {
                get
                {
                    CreateParams cp = base.CreateParams;
                    cp.ExStyle |= 0x20;
                    return cp;
                }
            }

            protected override void OnPaintBackground(PaintEventArgs e)
            {
                //Dont paint here
            }

        }

     

     

    and added the following code in the form1.designer.cs

    this.panel1 = new DoubleBufferPanel();

    private DoubleBufferPanel panel1;

     

    instead of using the following code in designer code

    this.panel1 = new System.Windows.Forms.Panel();

    private System.Windows.Forms.Panel panel1;

     

     

    But I still could not resolve repainting of the lines when I scroll the image. When I scroll the image the lines which are drawn on the image are redrawn which results in the lines flickering or blinking like. That is the lines drawn dont look as though they are painted permanently and fade away constantly until the scrolling is stopped.

     I hope this would help some other users :)

     

    Thank you

    • Marked as answer by SamSund Thursday, July 29, 2010 2:54 PM
    Thursday, July 29, 2010 2:53 PM
  • Thanks this helped !!!!
    Friday, September 21, 2012 2:54 PM