Question

I have two questions about polygons.

  1. Im drawing polygons to picturebox. The picturebox has slidebar. If i move with slidebar up or down, then polygons which are currently not vissible are deleted. Im working with C# just 2 months so Im still newbie. How to fix that problem?

  2. It is possible to click on polygons and with mouse move with them or change their size?

Best Regards

for (int i = 0; i < final_rng.Count; i++) 
{
    listPoint.Clear(); 
    for (int j = 0; j < final_rng[i].body.Count; j++)
    { 
       listPoint.Add(new Point(final_rng[i].body[j].X, final_rng[i].body[j].Y)); 
     }
//for (int j = 0; j < final_rng[i].body.Count; j++)
    grafika.FillPolygon(Brushes.Turquoise, listPoint.ToArray()); }
//for (int i = 0; i < final_rng.Count; i++)
Was it helpful?

Solution

If you draw directly on the PictureBox, the drawn polygons will be lost when the control is repainted (e.g. when you resize the window). A better way is to draw on a Bitmap and add then show it in the PictureBox. An example:

// A new bitmap with the same size as the PictureBox
var bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);

//Get the graphics objectm which we can use to draw
var graphics = Graphics.FromImage(bitmap);

//Draw stuff
graphics.FillRectangle(Brushes.Red, new Rectangle(0, 0, 500, 500));

//Show the bitmap with graphics image in the PictureBox
pictureBox1.Image = bitmap;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top