Map for WinForms | ComponentOne
Walkthrough / Displaying Geographic Coordinates on MouseOver
In This Topic
    Displaying Geographic Coordinates on MouseOver
    In This Topic

    Users can display geographical coordinates on hovering the mouse over the Map control using a TextBox. In this walkthrough, you will learn how to configure the Map control to 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.

     Map displaying geo coordinates while hovering

    Set up the application

    1. Create a new Windows Forms app.
    2. Drag and drop the Map control from the Toolbox onto the form.

    Configure Map control to display geographical coordinates

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

    1. Add a TextBox control, and Map control to your project.
    2. Set the TextBox control's Name property to "ShowCoordinates".
    3. In the properties window, change the MouseMove event name to "MouseMoveCoordinates" and press ENTER to add the MouseMoveCoordinates event handler to your project.
    4. Add the following code in the event:
      C#
      Copy Code
      private void MouseMoveCoordinates(object sender, MouseEventArgs e)
      {
      C1Map map= sender as C1Map;
      Point p = map.PointToClient(MousePosition);
      ShowCoordinates.Text = string.Format("{0:f6},{1:f6}", p.X, p.Y);
      }
    5. 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.