MindFusion WinForms Programmer's Guide
Adding Tooltips

This topic gives you detailed step-by-step instructions on how to add tooltips in your map. The tooltips are displayed when the mouse is over a region in the map.

1. Create a WinForms project and add the MapView control as described in the "Getting Started" section.

2. Add event handler for the MapElementHover event of your MapView instance.

C#  Copy Code

this.mapView.MapElementHover += new System.EventHandler<MindFusion.Mapping.WinForms.MapEventArgs>(this.mapView_MapElementHover);

VB.NET  Copy Code

AddHandler mapView.MapElementHover, AddressOf Me.mapView_MapElementHover

3. Add a System.Windows.Forms.ToolTip instance somewhere in the code behind file.

C#  Copy Code

ToolTip toolTip = new ToolTip();

VB.NET  Copy Code

Dim toolTip As ToolTip = New ToolTip

4. Handle the MapElementHover event - get the region under the mouse, construct and display the tooltip.

C#  Copy Code

private void mapView_MapElementHover(object sender, MapEventArgs e)
{
       //get the region under the mouse
       var region = e.MapElement as Shape;

       if (region != null)
       {
           //remove any previous tooltip
           if (toolTip != null)
           toolTip.Dispose();

           //Gets the DBF database row associated with the region
           var name = region.DatabaseRow["NAME_1"];

           //get the client coordinates of the mouse position
           var point = mapView.PointToClient(MousePosition);

           //initialize the tooltip
           toolTip = new ToolTip();
           toolTip.Show(name, mapView, point.X, point.Y + 20, 1000);
    }
}

VB.NET  Copy Code

Private Sub mapView_MapElementHover(ByVal sender As Object, ByVal e As MapEventArgs)
       'get the region under the mouse
       Dim region As var = CType(e.MapElement,Shape)
       If (Not (region) Is Nothing) Then
           'remove any previous tooltip
           If (Not (toolTip) Is Nothing) Then
               toolTip.Dispose
           End If
           'Gets the DBF database row associated with the region
           Dim name As var = region.DatabaseRow("NAME_1")
           'get the client coordinates of the mouse position
           Dim point As var = mapView.PointToClient(MousePosition)
           'initialize the tooltip
           toolTip = New ToolTip
           toolTip.Show(name, mapView, point.X, (point.Y + 20), 1000)
      End If
End Sub

5. Compile and run your project. By now you must have working tooltips.