About the Add a custom bookmarks MultiItem to the ToolbarControl Sample
[C#]
CreateBookmark.cs
using System;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.ADF.BaseClasses;
namespace MultiItemBookmarks
{
[ComVisible(false)]
public sealed class CreateBookmark : BaseCommand
{
private IHookHelper m_HookHelper = new HookHelperClass();
public CreateBookmark()
{
base.m_caption = "Create...";
base.m_category = "Developer Samples";
base.m_enabled = true;
base.m_message = "Creates a spatial bookmark based upon the current extent";
base.m_name = "Create...";
base.m_toolTip = "Create spatial bookmark";
}
public override void OnCreate(object hook)
{
m_HookHelper.Hook = hook;
}
public override void OnClick()
{
//Get a name for bookmark from the user
frmBookmark frm = new frmBookmark();
frm.ShowDialog();
int check = frm.Check;
string sName = "";
//OK button pressed
if (check == 1)
{
sName = frm.Bookmark;
}
if (sName == "") return;
//Get the focus map
IActiveView activeView = (IActiveView) m_HookHelper.FocusMap;
//Create a new bookmark
IAOIBookmark bookmark = new AOIBookmarkClass();
//Set the location to the current extent of the focus map
bookmark.Location = activeView.Extent;
//Set the bookmark name
bookmark.Name = sName;
//Get the bookmark collection of the focus map
IMapBookmarks mapBookmarks = (IMapBookmarks) m_HookHelper.FocusMap;
//Add the bookmark to the bookmarks collection
mapBookmarks.AddBookmark(bookmark);
}
}
}
[Visual Basic .NET]
CreateBookmark.vb
Option Strict Off
Option Explicit On
Imports ESRI.ArcGIS.Controls
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.ADF.BaseClasses
Friend Class CreateBookmarkCommand
Inherits BaseCommand
Private m_HookHelper As IHookHelper
Public Sub New()
MyBase.New()
m_HookHelper = New HookHelperClass
MyBase.m_caption = "Create..."
MyBase.m_category = "Developer Samples"
MyBase.m_enabled = True
MyBase.m_message = "Creates a spatial bookmark based upon the current extent"
MyBase.m_name = "Create..."
MyBase.m_toolTip = "Create spatial bookmark"
End Sub
Protected Overrides Sub Finalize()
m_HookHelper = Nothing
MyBase.Finalize()
End Sub
Public Overrides Sub OnCreate(ByVal hook As Object)
m_HookHelper.Hook = hook
End Sub
Public Overrides Sub OnClick()
'Get a name for bookmark from the user
Dim sName As String
sName = InputBox("Bookmark Name", "Spatial Bookmark")
If Trim(sName) = "" Then Exit Sub
'Get the focus map
Dim pActiveView As IActiveView
pActiveView = m_HookHelper.FocusMap
'Create a new bookmark
Dim pBookmark As IAOIBookmark
pBookmark = New AOIBookmarkClass
'Set the location to the current extent of the focus map
pBookmark.Location = pActiveView.Extent
'Set the bookmark name
pBookmark.Name = sName
'Get the bookmark collection of the focus map
Dim pMapBookmarks As IMapBookmarks
pMapBookmarks = m_HookHelper.FocusMap
'Add the bookmark to the bookmarks collection
pMapBookmarks.AddBookmark(pBookmark)
End Sub
End Class