Developer Reference Where Did I Click?

Where Did I Click (on the .NET control)?

So if the user is going to click on the chart we will need a click handler. Add one of these using the .NET form designer:

This will give you a empty function - below is C# (the VB.NET one will be quite similar)

private void S57Control1_MouseClick(object sender, MouseEventArgs e)
{
...
}

We have the pixel position (relative to the top left of the control) of the click in the MouseEventArgs passed to us. We need to convert this into a top that ENCX understands first.

Then we can use the GeoPix property of the S57Draw object to convert to lat lon.

In the function below I've displayed the position in a message box as well.

private void S57Control1_MouseClick(object sender, MouseEventArgs e)
{
    ENCX.PixelPoint mouse_position = new ENCX.PixelPoint();
    mouse_position.X = e.X;
    mouse_position.Y = e.Y;
    ENCX.GeoPoint lat_lon = m_draw.GeoPix.GeoPointFromPixelPoint(mouse_position);
    MessageBox.Show(lat_lon.Lat.ToString() + "," + lat_lon.Lon.ToString());
}

(The geopix can convert in the other direction to - Hint: you may need this if you are trying to detect whether the mouse click has "hit" some drawing that you have overlaid onto chart)

I've written a follow on from this article What did I click on? which describes how to query for S-57/ENC features under the mouse pointer.