www.pudn.com > AS15044.zip > HookActions.cs
// Copyright 2006 ESRI
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
//
// See use restrictions at /arcgis/developerkit/userestrictions.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.SystemUI;
namespace HookActions
{
public partial class HookActions : Form
{
public HookActions()
{
InitializeComponent();
}
IToolbarMenu m_ToolbarMenu;
private void HookActions_Load(object sender, EventArgs e)
{
//Add generic commands
axToolbarControl1.AddItem("esriControls.ControlsAddDataCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//Add map navigation commands
axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapPanTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsSelectFeaturesTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsSelectTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//Add globe navigation commands
axToolbarControl1.AddItem("esriControls.ControlsGlobeZoomInOutTool", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsGlobePanTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsGlobeFullExtentCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsGlobeSelectFeaturesTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//Create menu
m_ToolbarMenu = new ToolbarMenuClass();
//Set hook and command pool
m_ToolbarMenu.SetHook(axToolbarControl1);
m_ToolbarMenu.CommandPool = axToolbarControl1.CommandPool;
//Add custom commands
m_ToolbarMenu.AddItem(new hookActionsPan(), 0, -1, false, esriCommandStyles.esriCommandStyleTextOnly);
m_ToolbarMenu.AddItem(new hookActionsZoom(), 0, -1, false, esriCommandStyles.esriCommandStyleTextOnly);
m_ToolbarMenu.AddItem(new hookActionsFlash(), 0, -1, true, esriCommandStyles.esriCommandStyleTextOnly);
m_ToolbarMenu.AddItem(new hookActionsGraphic(), 0, -1, true, esriCommandStyles.esriCommandStyleTextOnly);
m_ToolbarMenu.AddItem(new hookActionsLabel(), 0, -1, false, esriCommandStyles.esriCommandStyleTextOnly);
m_ToolbarMenu.AddItem(new hookActionsCallout(), 0, -1, false, esriCommandStyles.esriCommandStyleTextOnly);
//Set buddy control
axToolbarControl1.SetBuddyControl(axMapControl1);
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
//Swap ToolbarControl buddy
if (tabControl1.SelectedIndex == 0)
axToolbarControl1.SetBuddyControl(axMapControl1);
else
axToolbarControl1.SetBuddyControl(axGlobeControl1);
}
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
//Popup menu
if (e.button == 2)
m_ToolbarMenu.PopupMenu(e.x, e.y, axMapControl1.hWnd);
}
private void axGlobeControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IGlobeControlEvents_OnMouseDownEvent e)
{
//Popup menu
if (e.button == 2)
m_ToolbarMenu.PopupMenu(e.x, e.y, axGlobeControl1.hWnd);
}
}
}