I
I
Ingvar Von Bjork2016-12-25 01:55:58
Images
Ingvar Von Bjork, 2016-12-25 01:55:58

How to fix disappearing polygon in pictureBox?

Own using this code:

curvePoints = new Point[5000];
for (int i = 1; i < 5000; i++)
{
    curvePoints[i] = new Point(i, Convert.ToInt32(10000/i));
}

Graphics g = pictureBox1.CreateGraphics();
Pen blackPen = new Pen(Color.Black, 1);
g.DrawPolygon(blackPen, curvePoints);

The graph appears in the pictureBox for a moment and then disappears. How to make it not disappear?
UPD0: in the course of research, I found that it depends on the width - if the width is small enough, then the graph does not disappear. But you need a width of 5000 pixels.
UPD1: when the event is restarted, the chart does not disappear either.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sumor, 2016-12-25
@DeboshiR

All drawing must be done in the Paint event handler, which occurs when the control is redrawn.
You draw in the control, but when the control is redrawn, it is cleared and "forgets" everything that was drawn. For this, you need to redraw the graph in the Paint event

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question