2

I have a panel resizes with the content and sometimes that content requires the panel to be 18660 px by 118320 px.

Now on a small panel I can draw a set of images with no problem and flickering but when the panel becomes that large it starts to flicker. I already have the doublebuffering property set to true and that works fine for the small panel but when it gets too large it starts flickering...

Does anyone have any idea on how this is prevented and how I can prevent it from flickering when I scroll.... I will put some code below to illustrate how I draw on the panel and such.

I am using lockbits to create a image that is the width and height of the visible area and not the entire panel:

for (y = 0; y < height; y++)
{
    if (y % size == 0)
    {
        if (showCons && y == 0)
            seq = cons;
        else
            seq = Sequences[(y / size) + vs];
        line = 0;
    }
    for (x = 0; x < width; x += size)
    {
        if ((offSet * 4) + (size * 4) < numBytes)
        {
            if (!HighLight || (HighLight && seq[(x + hs) / size] != refSequenceUp[(x + hs) / size]) == diff)
            {
                p = ColorImages[seq[(x / size) + hs]];
                if (x + size > width)
                {
                    Buffer.BlockCopy(p, line * size * 4, screen, offSet * 4, (width - x) * 4);
                    offSet += (width - x);
                }
                else
                {
                    Buffer.BlockCopy(p, line * size * 4, screen, offSet * 4, size * 4);
                    offSet += size;
                }
            }
            else
            {
                p = BlankImages[seq[(x / size) + hs]];
                if (x + size > width)
                {
                    Buffer.BlockCopy(p, line * size * 4, screen, offSet * 4, (width - x) * 4);
                    offSet += (width - x);
                }
                else
                {
                    Buffer.BlockCopy(p, line * size * 4, screen, offSet * 4, size * 4);
                    offSet += size;
                }
            }
        }
    }
    if (showCons && y > 0 && y == (size - 1))
    {
        y = -1;
        showCons = !showCons;
    }
    line++;
}

EDIT:

Ive overridden the onpaintbackground method and left it empty and it sort of stopped flickering but still the drawing takes way longer than on a small panel and when the onpaintbackground is overidden it leaves artefacts in the image...

  • Whyyyy do you draw the stuff on the panel thats not even visible? Just draw the stuff thats actualy visible – Vajura Oct 21 '14 at 09:47
  • @Vajura I am only drawing the visible area because the width and height in this case is the width and height of the scrollviewer that is the parent of the panel that im painting on – Sjoerd Redeker Oct 21 '14 at 09:58
  • besides changing the whole design to something with smaller tiles I would look into how you invalidate the panel..the whole thing or only the visible/changed/scrolled parts? – TaW Oct 21 '14 at 10:48
  • I was invalidating the entire panel but am now invalidating just the visible part. When the panel itself is small it takes 20ms tops to draw on it but when the panel is large it takes more than double that (45 - 50ms). the g.DrawImage() is the one that is taking much more time. Why is a drawing method taking longer on a large panel than on a small panel when the to be drawn image is the same size? – Sjoerd Redeker Oct 21 '14 at 11:13
  • I don't know, but in order to draw on such a huge Graphics some expensive preparations may be necessary. Remember: Even if you only draw on the visible part there are `Graphics` calls, like `Clear` that will affect the whole size.. – TaW Oct 21 '14 at 12:46

0 Answers0