Hit-testing a polygon?

D

Dave Veeneman

What is the simplest way to perform hit-testing on a polygon? A user control
I'm writing draws a document with a 'dog-ear' in the upper right corner. I
want the user to be able to click on the dogiear to perform an action. The
cursor should change when the mouse enters the dog-ear (to indicate that it
is 'live'), change back when the user leaves the dog-ear, and the program
should know when the user clicks inside the dog-ear.

I'm familair with mouse events, but I'm not sure how to hit-test a polygon.
I have the coordinates of the polygon, and it looks like I create a region
from the polygon, then use the Region.IsVisible() method to determine
whether the mouse coordinates are inside the region. Is that the way to do
it? Is there a simpler way? Thanks
 
H

Herfried K. Wagner [MVP]

* "Dave Veeneman said:
I'm familair with mouse events, but I'm not sure how to hit-test a polygon.
I have the coordinates of the polygon, and it looks like I create a region
from the polygon, then use the Region.IsVisible() method to determine
whether the mouse coordinates are inside the region. Is that the way to do
it? Is there a simpler way? Thanks

I think that's the preferred way. Nevertheless, notice that 'IsVisible'
may have bad performance when used on a complex region.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
 
J

Justin Weinberg

Depending on how complex the figure is, you can also bound it with an
invisible rectangle and hit test the rectangle with .Contains instead. You
could also use a series of rectangles and tile it over the figure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top