Why does the panel autoscroll erase the lines?

0

I am occupying generating lines that link the vertices of a tree, but it does not generate the lines that are outside the range of the panel, even though I have the autoscroll in "true", and when I go down to review the vertices, the lines that were up disappear, this is the code

for (int ñ = 1; ñ <indice+bug; ñ++)//grega lineas
        {
            Pen myPen;
            myPen = new Pen(Color.Black);
            Graphics formGraphics;
            formGraphics = panel1.CreateGraphics();
            formGraphics.DrawLine(myPen, pos[ñ, 1] + 25, pos[ñ, 0], pos[cpila[ñ, 3], 1] + 25, pos[cpila[ñ, 3], 0]);
            myPen.Dispose();
            formGraphics.Dispose();



        }
    
asked by Edgar Diaz 07.02.2017 в 10:42
source

2 answers

0

You can execute the following method, when you scroll:

private void panel1_Scroll(object sender, ScrollEventArgs e)
{
    panel1.Invalidate();
}
    
answered by 07.02.2017 в 10:58
0

The question is not very clear, but I suspect that the problem is that you are trying to draw on the panel in some external method, and what is happening to you is that by invalidating the control, you obviously delete what you drew.

What you should do is subscribe to the event Paint of Panel and do something like this:

private void panel1_Paint(object sender, PaintEventArgs e)
{
     Pen myPen;
     myPen = new Pen(Color.Black);
     for (int ñ = 1; ñ <indice+bug; ñ++)//grega lineas
     {

         e.Graphics.DrawLine(myPen, pos[ñ, 1] + 25, pos[ñ, 0], pos[cpila[ñ, 3], 1] + 25, pos[cpila[ñ, 3], 0]);
     }
     myPen.Dispose();
}

Anyway, if the panel has scroll I doubt that it will work very well, since the positions in which you draw will vary.

    
answered by 07.02.2017 в 11:33