VB.NET•Convert Pixels to Latitude and Longitude

Listing 4. The LatLongEditorUI class is a standard borderless Windows Form with a few public properties (EditorService and GetLocation) added to support the custom property editor features. Other than that, it's a plain old boring form with ordinary events.

Public Class LatLongEditorUI
   Inherits System.Windows.Forms.UserControl

   Private propService _
      As IWindowsFormsEditorService
   Private mLocation As LatLong
   Private lastLat As String = "0.00N"
   Private lastLong As String = "0.00W"

   Public Property EditorService() _
      As IWindowsFormsEditorService
      ' ----- Interface to underlying service.
         Return propService
      End Get
      Set(ByVal Value _
         As IWindowsFormsEditorService)
         propService = Value
      End Set
   End Property

   Public Property GeogLocation() As LatLong
      ' ----- This is how the editor class
      '       communicates with the UI.
         Return mLocation
      End Get
      Set(ByVal Value As LatLong)
         mLocation = Value
      End Set
   End Property

   Private Sub MapImage_Click(...)
      ' ----- Save the clicked location.
      mLocation.Latitude = lastLat
      mLocation.Longitude = lastLong
   End Sub

   Private Sub MapImage_MouseMove(...)
      ' ----- Detemines and displays lat/long.
      '       Sets lastLat, lastLong
   End Sub
End Class