如何在运行时使用C#给出所有点时偏移多边形 [英] How to offset a polygon when all points are given at the run time using C#

查看:119
本文介绍了如何在运行时使用C#给出所有点时偏移多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过点击图片框中的点创建了一个多边形。



所以这些点是在运行时用户定义的。



我想在它上面做一个偏移多边形。



如何在所有边上做多边形偏移。



任何人都可以给我代码











请帮我创建偏移多边形

I created a polygon by clicking points in the picture box.

So the points are user defined at the run time.

I want to make an offset polygon over it.

How to make polygon offset at all sides.

Can anyone give me the code





Please help me to create an offset polygon

推荐答案

假设您遇到困难的部分是这样的:

Assuming that the part you are having difficulty with is this:
case MouseButtons.Middle:
                    Point[] offsetPoint=polygonPoints.ToArray();

                    int resizeValue = 10;
offsetPoint.Select(x => new Point(x.X*resizeValue, x.Y*resizeValue));
graphics.DrawPolygon(new Pen(Color.Green), offsetPoint);
                        polygonPoints.Clear();

                    break;



然后它确实抵消了一个点 - 但是你然后抛出它的方式...

Select方法创建一个新的Enumerable,这是你想要的,但是...它不会取代旧的。

可能,你想要做的是:


Then it does offset a point - but you then throw it way...
The Select method creates a new Enumerable, which is what you want, but...it doesn't replace the old one.
Probably, what you want to do is:

case MouseButtons.Middle:
                    Point[] offsetPoint=polygonPoints.ToArray();

                    int resizeValue = 10;
                    offsetPoint = offsetPoint.Select(x => new Point(x.X*resizeValue, x.Y*resizeValue)).ToArray();
                    graphics.DrawPolygon(new Pen(Color.Green), offsetPoint);
                    polygonPoints.Clear();

                    break;

哪些存储了新的偏移点,以便您可以使用它们。

Which stores the newly offset Points so you can use them.

这篇关于如何在运行时使用C#给出所有点时偏移多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆