You could use the
System.Drawing.Region[
^] class and its
IsVisible()[
^] method.
Will need quite some manual work to create the Regions for each country. Or you can get geodesic data you can convert.
When done with that, you can get the clicked country from the mouse pointer's position.
Here is an example:
public static void Example()
{
System.Drawing.Region someCountryOutline = new Region(
new System.Drawing.Drawing2D.GraphicsPath(
new PointF[]{
new PointF(0F,0F),
new PointF(200F,0F),
new PointF(220F, 20F),
new PointF(220F, 200F),
new PointF(0F,200F)
},
new byte[]{
(byte)System.Drawing.Drawing2D.PathPointType.Start,
(byte)System.Drawing.Drawing2D.PathPointType.Line,
(byte)System.Drawing.Drawing2D.PathPointType.Line,
(byte)System.Drawing.Drawing2D.PathPointType.Line,
(byte)(System.Drawing.Drawing2D.PathPointType.Line
|System.Drawing.Drawing2D.PathPointType.CloseSubpath)
}
)
);
if (someCountryOutline.IsVisible(WorldMapControl.MousePosition))
{
Console.WriteLine("Mouse within country borders.");
}
}
You will, however need to change the co-ordinates in some co-ordinate system of your choice. You will end up with one Region per country. The
new Region()
stuff belongs in some initialization code. The
IsVisible()
part will be processed in one of the mouse event handlers.