ComponentOne Maps for WPF and Silverlight
Maps for WPF and Silverlight Task-Based Help / Displaying Geographic Coordinates on Mouseover
In This Topic
    Displaying Geographic Coordinates on Mouseover
    In This Topic

    In this topic, you will add code to your project that will return the geographical coordinates of the current mouse position. These geographical coordinates will then be written as a string to the Text property of a TextBox control.

    To get the geographical coordinates of the current mouse position, complete the following steps:

    1. Add a StackPanel, a TextBox control, and a C1Maps control to your project.
    2. In the Objects and Timeline panel, rearrange the controls so they appears as follows:

    3. Set the StackPanel's properties as follows:
      • Locate the Width property and click its glyph to set the Width property to Auto.
      • Locate the Height property and click its glyph to set the Height property to Auto.
    4. Set the TextBox control's Name property to "ShowCoordinates".
    5. Set the C1Maps control's properties as follows:
      • Set the Width property to "350".
      • Set the Height property to "250".
    6. Select the C1Maps control and then, in the Properties panel, click the Events button .
    7. In the MouseMove text box, enter "MouseMoveCoordinates" and press ENTER to add the MouseMoveCoordinates event handler to your project.
    8. Replace the code comment with the following code:

      Visual Basic
      Copy Code
      Dim map As C1Maps = TryCast(sender, C1Maps)
      Dim p As Point = map.ScreenToGeographic(e.GetPosition(map))
      ShowCoordinates.Text = String.Format("{0:f6},{1:f6}", p.X, p.Y)
      

      C#
      Copy Code
      C1Maps map = sender as C1Maps;
      Point p = map.ScreenToGeographic(e.GetPosition(map));
      ShowCoordinates.Text = string.Format("{0:f6},{1:f6}", p.X, p.Y);
      

    9. Import the following namespace:

      Visual Basic
      Copy Code
      Imports C1.WPF.C1Maps
      

      C#
      Copy Code
      using C1.WPF.C1Maps;
      

    10. Press F5 to run the project. Once the project is loaded, run your cursor over the map and observe that geographical coordinates appear in the text box.

    See Also