问题描述
我正在使用 .NET 绘制图表,我想在用户单击对象时突出显示它们。将图形完全包含在矩形中很容易:
I'm using .NET to draw a diagram, and I want to highlight objects when the user performs a click on them. It is easy when a figure is fully contained in a rectangle:
if (figure.Bounds.Contains(p)) // bounds is a rectangle
但是,如果图形复杂,我不知道如何管理它 GraphicsPath
。
But I don't know how to manage it if the figure is a complex GraphicsPath
.
我为以下对象定义了以下 GraphicsPath
:图(绿色圆圈)。
I have defined the following GraphicsPath
for the figure (the green circle).
我想在用户单击该图时突出显示该图。 我想知道 GraphicsPath
中是否包含 Point
。
I want to highlight the figure when the user click on it. I would like to know if a Point
is contained in that GraphicsPath
.
有什么想法吗?预先感谢。
Any ideas? Thanks in advance.
推荐答案
我不知道 DrawingPath (您可能是指图形。 DrawPath),但 GraphicsPath
具有方法来检查路径中是否有点。
I don't know a DrawingPath (you mean probably; graphics.DrawPath) but a GraphicsPath
has the IsVisible method to check if a point is in the path.
bool isInPath = graphicsObj.IsVisible(point)
这篇关于如何知道GraphicsPath是否在C#中包含一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!