How can i draw in picturebox a polygon which is marked on the edges

纵然是瞬间 提交于 2020-01-02 11:06:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!