Tom van Stiphout wrote:
On Wed, 30 Nov 2005 10:03:11 GMT, Les Stout <an*******@devdex.com>
wrote:
You'll want to use what the help file and all the books call a
"parameter query".
To find out what province was clicked, perhaps each can have a
different color. There are ways to get the color of the pixel that was
clicked, e.g. there is a Windows API that can do this (sorry I forgot
the name).
-Tom.
I like Tom's idea. If you can find the API function to return the
pixel information it would be a very elegant solution to the problem.
Maybe:
Private Declare Function GetPixel Lib "gdi32.dll" (ByVal hdc As Long,
ByVal x As Long, ByVal y As Long) As Long
It is rumored that a call to GetDeviceCaps can determine whether or not
GetPixel can be used on a particular device.
If not, I have not yet proven the following but it's the best my
intuition can do at the moment. Also, I believe that some graphics
books show some standard methods for determining whether or not a point
is in a region bounded by line segments. Note that HTML has this
capability built-in :-).
Assuming the region is a simple polygon (possibly concave in places),
make a table that consists of the point coordinates of the polygon in
order, say counterclockwise (CCW). It should look something like:
tblBoundaries
BID Autonumber Primary Key
ProvinceID Long Foreign Key
VertexID Long
VX Long (Twips)
VY Long (Twips)
I am assuming you are getting X and Y from the MouseDown event (perhaps
Detail_MouseDown). X is positive to the right and Y is positive down.
Let the envelope region of a line segment be defined as the region
swept out by the line segment along its normal in both directions. If
the point that was clicked does not lie in any of the envelopes of its
boundary then it must lie outside the region. Of the boundary segments
whose envelope contains the point find the closest one. Decide what
you want to do if a point on the vertex or boundary is chosen. If CCW
was chosen, the point is interior if it lies to the left when going
from the smaller numbered vertex to the larger (except for N back to
1). I believe the distance (or its square for simplicity) from a point
to a line as well as an envelope test done by seeing if the point lies
within two lines can be improved using vector math (directed line
segments correspond 1-1 with vectors). Until a region is found, the
code would need to loop through each ProvinceID. I'm guessing that a
public function utilizing recordsets will be needed to implement
obtaining the ProvinceID, if any, of the location clicked. When you
can obtain the ProvinceID you can use a single report that covers any
province. As you can see, this method involves a lot more work than
using Tom's idea even if you cut some corners (literally :-)). Post
back if you'd like me to explore this idea further.
James A. Fortune