How to display MapControl and ToolbarControl information on a status bar


Summary
This topic describes how to display information about the ToolBarControl, MapControl, and control commands on a System.Windows.Forms.StatusBar control.

Displaying MapControl and ToolbarControl information on a status bar

Do the following steps to display information about the toolbar item that has focus and the mouse location on a System.Windows.Forms.StatusBar:
  1. Add and configure two StatusBar panels.
  2. Determine whether the mouse pointer is over a toolbar item by calling the HitTest method within the IToolbarControlEvents.OnMouseMove event. If the mouse pointer is over an IToolbarItem, the text of the first StatusBar panel is set to the message of the IToolbarItem.Command.
  3. Set the text of the second StatusBar panel to the mouse coordinates in map units in the IMapControlEvents2.OnMouseMove event. The IMapControlEvent2.OnMapReplaced event can be used to keep track of the MapControl's MapUnits.

    See the following code example:
[C#]
//Set StatusBar properties.
StatusBarPanel panel1 = new StatusBarPanel();
StatusBarPanel panel2 = new StatusBarPanel();
statusBar1.Panels.Add(panel1);
statusBar1.Panels.Add(panel2);
statusBar1.Panels[0].Style = StatusBarPanelStyle.Text;
statusBar1.Panels[1].Style = StatusBarPanelStyle.Text;
statusBar1.Panels[0].BorderStyle = StatusBarPanelBorderStyle.Sunken;
statusBar1.Panels[1].BorderStyle = StatusBarPanelBorderStyle.Sunken;
statusBar1.Panels[0].Width = (axMapControl1.Width) / 5 * 3;
statusBar1.Panels[1].Width = (axMapControl1.Width) / 5 * 2;
statusBar1.Panels[0].Text = "";
statusBar1.Panels[1].Text = "";
statusBar1.ShowPanels = true;
[VB.NET]
'Set StatusBar properties.
StatusBar1.Panels.Add(0).Style = StatusBarPanelStyle.Text
StatusBar1.Panels.Add(1).Style = StatusBarPanelStyle.Text
StatusBar1.Panels(0).BorderStyle = StatusBarPanelBorderStyle.Sunken
StatusBar1.Panels(1).BorderStyle = StatusBarPanelBorderStyle.Sunken
StatusBar1.Panels(0).Width = (AxMapControl1.Width) / 5 * 3
StatusBar1.Panels(1).Width = (AxMapControl1.Width) / 5 * 2
StatusBar1.Panels(0).Text = ""
StatusBar1.Panels(1).Text = ""
StatusBar1.ShowPanels = True
[C#]
private void axToolbarControl1_OnMouseMove(object sender,
    ESRI.ArcGIS.Controls.IToolbarControlEvents_OnMouseMoveEvent e)
{
    //Determine if the mouse is over an item.
    int index = axToolbarControl1.HitTest(e.x, e.y, false);
    if (index !=  - 1)
    {
        //Get a reference to the ToolbarItem interface.
        IToolbarItem toolbarItem = axToolbarControl1.GetItem(index);
        //Set statusbar text.
        statusBar1.Panels[0].Text = toolbarItem.Command.Message;
    }
    else
    {
        statusBar1.Panels[0].Text = "";
    }
}

private void axMapControl1_OnMouseMove(object sender,
    ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
{
    statusBar1.Panels[1].Text = e.mapX.ToString(".00") + " " + e.mapY.ToString(".00")
        + " " + sMapUnits;
}
[VB.NET]
Private Sub AxToolbarControl1_OnMouseMove(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Controls.IToolbarControlEvents_OnMouseMoveEvent) Handles AxToolbarControl1.OnMouseMove
    'Determine if the mouse is over an item.
    Dim lIndex As Integer
    lIndex = AxToolbarControl1.HitTest(e.x, e.y, False)
    Dim pToolbarItem As IToolbarItem
    If lIndex <> -1 Then
        'Get a reference to the ToolbarItem interface.
        pToolbarItem = AxToolbarControl1.GetItem(lIndex)
        'Set statusbar text.
        StatusBar1.Panels(0).Text = pToolbarItem.Command.Message
    Else
        StatusBar1.Panels(0).Text = ""
    End If
End Sub

Private Sub AxMapControl1_OnMouseMove(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent) Handles AxMapControl1.OnMouseMove
    'Set statusbar text.
    StatusBar1.Panels(1).Text = Format(e.mapX, ".00") & " " & Format(e.mapY, ".00") & " " & sMapUnits
End Sub
The following code example converts map units to text, as sMapUnits is used in the previous MapControl's OnMouseMove event:
[C#]
esriUnits mapUnits = axMapControl1.MapUnits;
switch (mapUnits)
{
    case esriUnits.esriCentimeters:
        sMapUnits = "Centimeters";
        break;
    case esriUnits.esriDecimalDegrees:
        sMapUnits = "Decimal Degrees";
        break;
    case esriUnits.esriDecimeters:
        sMapUnits = "Decimeters";
        break;
    case esriUnits.esriFeet:
        sMapUnits = "Feet";
        break;
    case esriUnits.esriInches:
        sMapUnits = "Inches";
        break;
    case esriUnits.esriKilometers:
        sMapUnits = "Kilometers";
        break;
    case esriUnits.esriMeters:
        sMapUnits = "Meters";
        break;
    case esriUnits.esriMiles:
        sMapUnits = "Miles";
        break;
    case esriUnits.esriMillimeters:
        sMapUnits = "Millimeters";
        break;
    case esriUnits.esriNauticalMiles:
        sMapUnits = "NauticalMiles";
        break;
    case esriUnits.esriPoints:
        sMapUnits = "Points";
        break;
    case esriUnits.esriUnknownUnits:
        sMapUnits = "Unknown";
        break;
    case esriUnits.esriYards:
        sMapUnits = "Yards";
        break;
}
[VB.NET]
Dim pMapUnits As esriUnits
pMapUnits = AxMapControl1.MapUnits
If pMapUnits = esriUnits.esriCentimeters Then
    sMapUnits = "Centimeters"
ElseIf pMapUnits = esriUnits.esriDecimalDegrees Then
    sMapUnits = "Decimal Degrees"
ElseIf pMapUnits = esriUnits.esriDecimeters Then
    sMapUnits = "Decimeters"
ElseIf pMapUnits = esriUnits.esriFeet Then
    sMapUnits = "Feet"
ElseIf pMapUnits = esriUnits.esriInches Then
    sMapUnits = "Inches"
ElseIf pMapUnits = esriUnits.esriKilometers Then
    sMapUnits = "Kilometers"
ElseIf pMapUnits = esriUnits.esriMeters Then
    sMapUnits = "Meters"
ElseIf pMapUnits = esriUnits.esriMiles Then
    sMapUnits = "Miles"
ElseIf pMapUnits = esriUnits.esriMillimeters Then
    sMapUnits = "Millimeters"
ElseIf pMapUnits = esriUnits.esriNauticalMiles Then
    sMapUnits = "NauticalMiles"
ElseIf pMapUnits = esriUnits.esriPoints Then
    sMapUnits = "Points"
ElseIf pMapUnits = esriUnits.esriUnknownUnits Then
    sMapUnits = "Unknown"
ElseIf pMapUnits = esriUnits.esriYards Then
    sMapUnits = "Yards"
End If


See Also:

ToolbarControl class
IToolbarControl interface
IToolbarItem interface
MapControl class




Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced