问题
i tried in that way but i didnt get the needed results:
System.Drawing.Point[] p = new System.Drawing.Point[6];
p[0].X = 0;
p[0].Y = 0;
p[1].X = 53;
p[1].Y = 111;
p[2].X = 114;
p[2].Y = 86;
p[3].X = 34;
p[3].Y = 34;
p[4].X = 165;
p[4].Y = 7;
g = PictureBox1.CreateGraphics();
g.DrawPolygon(pen1, p);
what i want to do is to draw a polygon in picturebox which is defined with diffrent colors and according to the rates (the number of corner and coordinates of the edges )
回答1:
Create an xOffset variable, set it to be 30, and add that to every X value. Let yOffset equal 50 and add it to all your Ys.
回答2:
Simply do this to your graphics object:
g.TranslateTransform(30, 40);
before drawing onto it.
And of course you shouldn't use PictureBox1.CreateGraphics();
but draw things you want to persist in the Paint
event with e.Graphics
!..
来源:https://stackoverflow.com/questions/12081978/how-can-i-draw-in-picturebox-a-polygon-which-is-marked-on-the-edges