如何扩展一条线以形成一个矩形或区域



我在。net2工作,所以不能访问。net3中的Line类,虽然我不确定这是否会起作用。

但是我有一条线(2个点)

,我想把它的宽度扩展到4,也就是说,就像绘图上的drawLine一样,但是我找不到一个简单的方法来获取区域/图形路径或矩形。

有人知道吗?如果直线可以是任意方向

我已经找到了这样做的方法,

GraphicsPath gfxPath = new GraphicsPath();
gfxPath.AddLine(line.x1, line.y1, line.x2, line.y2);
gfxPath.Widen(new Pen(Color.Blue, lineThickness));//lineThinkness is all that matters
Region reg = new Region(gfxPath);
if (reg.IsVisible(mousePoint)) // return true if the mousePoint is within the Region.

通过lineThickness来扩大行,然后你可以用它来检查是否有点或矩形等在里面。

最新更新