[英]Draw a Grid over a Picturebox in c#
I am trying to make a tool in c# which allows the user to put a grid on the screen on a picturebox. 我正在尝试使用c#创建一个工具,该工具允许用户在图片框的屏幕上放置网格。 At the moment i don't know how to do this, so when a button is clicked, the picturebox comes up with a grid.
目前我不知道该怎么做,所以当单击一个按钮时,图片框会显示一个网格。 It needs to be a grid which is spaced out enough that users can find out locations of objects on the picture in the picturebox.
它必须是一个间距足够大的网格,以便用户可以在图片框中找到对象在图片上的位置。 Help with what code i can use to do this would be very helpful as i was going to use ControlPaint.DrawGrid but not sure of the values i need to put in it to get my desired effect?
帮助我使用什么代码可以做到这一点非常有用,因为我将要使用ControlPaint.DrawGrid,但是不确定我需要输入的值才能达到我想要的效果?
Thanks 谢谢
Form the Documentation od controlpaint.Drawgrid, 形成controlod.Drawgrid的文档 ,
I suppose you need to decide on the cell size in x- amd y-direction and pass this as a size parameter to Drawgrid: 我想您需要确定x-amd y方向上的像元大小,并将其作为大小参数传递给Drawgrid:
public static void DrawGrid(
Graphics graphics,
Rectangle area,
Size pixelsBetweenDots,
Color backColor
)
for example, a 100*200 pixels square grid would be generated by 例如,将通过以下方式生成100 * 200像素的正方形网格:
setting graphcis to the context you want to draw upon, 将graphcis设置为您要绘制的上下文,
Setting area to the top left right and bottom parameters of your image 将区域设置为图像的左上角,右下角和底部参数
setting size.x to 100 and size.y to 200 将size.x设置为100,将size.y设置为200
setting color to any color you like. 将颜色设置为您喜欢的任何颜色。
Update Something like this should do. 更新类似的事情应该做。
Rectangle myRect = new System.drawings.Rectangle();
myRect.Location := new System.Drawing.Point(0,0);
myRect.Height = 50;
myRect.Width = 50;
Drawgrid(FromImage(yourImage), mygrid , yourImage.Size, System.Drawing.Color.Black);
Disclaimer: i don't develope in c#, so above code is not tested for anything. 免责声明:我不是用C#开发的,所以上面的代码没有经过任何测试。 I just picked stuff from the documentation (msdn).
我只是从文档(msdn)中挑选了东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.