Click here to get the sample associated with this walkthrough.
| Development licensing | Deployment licensing |
|---|---|
| Engine Developer Kit | Engine Runtime |
| ArcView | |
| ArcEditor | |
| ArcInfo |
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.esriSystem;
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Controls
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.SystemUI
Imports ESRI.ArcGIS.esriSystem
private void MapViewer_Load(object sender, System.EventArgs e)
{
//Load a pre-authored map document into the PageLayoutControl using relative paths.
string fileName = @
"..\..\..\..\data\GulfOfStLawrence\Gulf_of_St._Lawrence.mxd";
if (axPageLayoutControl1.CheckMxFile(fileName))
axPageLayoutControl1.LoadMxFile(fileName, "");
}
Private Sub MapViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Load a pre-authored map document into the PageLayoutControl using realative paths.
Dim sFileName As String = "..\..\..\..\data\GulfOfStLawrence\Gulf_of_St._Lawrence.mxd"
If AxPageLayoutControl1.CheckMxFile(sFileName) Then
AxPageLayoutControl1.LoadMxFile(sFileName)
End If
End Sub
private void axPageLayoutControl1_OnPageLayoutReplaced(object sender,
IPageLayoutControlEvents_OnPageLayoutReplacedEvent e)
{
//Load the same pre-authored map document into the MapControl.
axMapControl1.LoadMxFile(axPageLayoutControl1.DocumentFilename, null, null);
//Set the extent of the MapControl to the full extent of the data.
axMapControl1.Extent = axMapControl1.FullExtent;
}
Private Sub AxPageLayoutControl1_OnPageLayoutReplaced(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnPageLayoutReplacedEvent) Handles AxPageLayoutControl1.OnPageLayoutReplaced
'Load the same pre-authored map document into the MapControl.
AxMapControl1.LoadMxFile(AxPageLayoutControl1.DocumentFilename)
'Set the extent of the MapControl to the full extent of the data.
AxMapControl1.Extent = AxMapControl1.FullExtent
End Sub
private void MapViewer_Load(object sender, System.EventArgs e)
{
//Set buddy controls.
axTOCControl1.SetBuddyControl(axPageLayoutControl1);
axToolbarControl1.SetBuddyControl(axPageLayoutControl1);
//Load a pre-authored map document into the PageLayoutControl using relative paths.
}
Private Sub MapViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Set buddy controls.
AxTOCControl1.SetBuddyControl(AxPageLayoutControl1)
AxToolbarControl1.SetBuddyControl(AxPageLayoutControl1)
'Load a pre-authored map document into the PageLayoutControl using realative paths.
End Sub
private void MapViewer_ResizeBegin(object sender, EventArgs e)
{
//Suppress data redraw and draw bitmap instead.
axMapControl1.SuppressResizeDrawing(true, 0);
axPageLayoutControl1.SuppressResizeDrawing(true, 0);
}
Private Sub MapViewer_ResizeBegin(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.ResizeBegin
'Suppress data redraw and draw bitmap instead.
AxMapControl1.SuppressResizeDrawing(True, 0)
AxPageLayoutControl1.SuppressResizeDrawing(True, 0)
End Sub
private void MapViewer_ResizeEnd(object sender, EventArgs e)
{
//Stop bitmap draw and draw data.
axMapControl1.SuppressResizeDrawing(false, 0);
axPageLayoutControl1.SuppressResizeDrawing(false, 0);
}
Private Sub MapViewer_ResizeEnd(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.ResizeEnd
'Stop bitmap draw and draw data.
AxMapControl1.SuppressResizeDrawing(False, 0)
AxPageLayoutControl1.SuppressResizeDrawing(False, 0)
End Sub
private void MapViewer_Load(object sender, EventArgs e)
{
//Add generic commands.
axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsAddDataCommand", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//Add page layout navigation commands.
axToolbarControl1.AddItem("esriControls.ControlsPageZoomInTool", - 1, - 1,
true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsPageZoomOutTool", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsPagePanTool", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsPageZoomWholePageCommand", -
1, - 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//Add map navigation commands.
axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", - 1, - 1,
true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapPanTool", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", - 1,
- 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem(
"esriControls.ControlsMapZoomToLastExtentBackCommand", - 1, - 1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem(
"esriControls.ControlsMapZoomToLastExtentForwardCommand", - 1, - 1, false,
0, esriCommandStyles.esriCommandStyleIconOnly);
//Add map inquiry commands.
axToolbarControl1.AddItem("esriControls.ControlsMapIdentifyTool", - 1, - 1,
true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapFindCommand", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapMeasureTool", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//Set buddy controls.
}
Private Sub MapViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Add generic commands.
AxToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsAddDataCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
'Add page layout navigation commands.
AxToolbarControl1.AddItem("esriControls.ControlsPageZoomInTool", -1, -1, True, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsPageZoomOutTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsPagePanTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsPageZoomWholePageCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
'Add map navigation commands.
AxToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", -1, -1, True, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapPanTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentBackCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentForwardCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
'Add map inquiry commands.
AxToolbarControl1.AddItem("esriControls.ControlsMapIdentifyTool", -1, -1, True, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapFindCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapMeasureTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
'Set buddy controls.
End Sub
public partial class MapViewer: Form
{
//The pop-up menu.
private IToolbarMenu m_ToolbarMenu;
}
Public Class MapViewer
'The pop-up menu.
Private m_pToolbarMenu As IToolbarMenu
End Class
private void MapViewer_Load(object sender, EventArgs e)
{
//Add map inquiry commands.
//Create a new ToolbarMenu.
m_ToolbarMenu = new ToolbarMenuClass();
//Share the ToolbarControl's command pool.
m_ToolbarMenu.CommandPool = axToolbarControl1.CommandPool;
//Set the hook to the PageLayoutControl.
m_ToolbarMenu.SetHook(axPageLayoutControl1);
//Add commands to the ToolbarMenu.
m_ToolbarMenu.AddItem("esriControls.ControlsPageZoomInFixedCommand", - 1, -
1, false, esriCommandStyles.esriCommandStyleIconAndText);
m_ToolbarMenu.AddItem("esriControls.ControlsPageZoomOutFixedCommand", - 1,
- 1, false, esriCommandStyles.esriCommandStyleIconAndText);
m_ToolbarMenu.AddItem("esriControls.ControlsPageZoomWholePageCommand", - 1,
- 1, false, esriCommandStyles.esriCommandStyleIconAndText);
m_ToolbarMenu.AddItem(
"esriControls.ControlsPageZoomPageToLastExtentBackCommand", - 1, - 1,
true, esriCommandStyles.esriCommandStyleIconAndText);
m_ToolbarMenu.AddItem(
"esriControls.ControlsPageZoomPageToLastExtentForwardCommand", - 1, - 1,
false, esriCommandStyles.esriCommandStyleIconAndText);
//Set buddy controls.
}
Private Sub MapViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Add map inquiry commands.
'Create a new ToolbarMenu.
m_pToolbarMenu = New ToolbarMenuClass()
'Share the ToolbarControl's command pool.
m_pToolbarMenu.CommandPool = AxToolbarControl1.CommandPool
'Set the hook to the PageLayoutControl
m_pToolbarMenu.SetHook(AxPageLayoutControl1)
'Add commands to the ToolbarMenu.
m_pToolbarMenu.AddItem("esriControls.ControlsPageZoomInFixedCommand", -1, -1, False, esriCommandStyles.esriCommandStyleIconAndText)
m_pToolbarMenu.AddItem("esriControls.ControlsPageZoomOutFixedCommand", -1, -1, False, esriCommandStyles.esriCommandStyleIconAndText)
m_pToolbarMenu.AddItem("esriControls.ControlsPageZoomWholePageCommand", -1, -1, False, esriCommandStyles.esriCommandStyleIconAndText)
m_pToolbarMenu.AddItem("esriControls.ControlsPageZoomPageToLastExtentBackCommand", -1, -1, True, esriCommandStyles.esriCommandStyleIconAndText)
m_pToolbarMenu.AddItem("esriControls.ControlsPageZoomPageToLastExtentForwardCommand", -1, -1, False, esriCommandStyles.esriCommandStyleIconAndText)
'Set buddy controls.
End Sub
private void axPageLayoutControl1_OnMouseDown(object sender,
IPageLayoutControlEvents_OnMouseDownEvent e)
{
//Pop-up the ToolbarMenu.
if (e.button == 2)
m_ToolbarMenu.PopupMenu(e.x, e.y, axPageLayoutControl1.hWnd);
}
Private Sub AxPageLayoutControl1_OnMouseDown(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent) Handles AxPageLayoutControl1.OnMouseDown
'Pop-up the ToolbarMenu.
If e.button = 2 Then
m_pToolbarMenu.PopupMenu(e.x, e.y, AxPageLayoutControl1.hWnd)
End If
End Sub
private void MapViewer_Load(object sender, EventArgs e)
{
//Add map inquiry commands.
//Create a new ToolbarPalette.
IToolbarPalette toolbarPalette = new ToolbarPaletteClass();
//Add commands and tools to the ToolbarPalette.
toolbarPalette.AddItem("esriControls.ControlsNewMarkerTool", - 1, - 1);
toolbarPalette.AddItem("esriControls.ControlsNewLineTool", - 1, - 1);
toolbarPalette.AddItem("esriControls.ControlsNewCircleTool", - 1, - 1);
toolbarPalette.AddItem("esriControls.ControlsNewEllipseTool", - 1, - 1);
toolbarPalette.AddItem("esriControls.ControlsNewRectangleTool", - 1, - 1);
toolbarPalette.AddItem("esriControls.ControlsNewPolygonTool", - 1, - 1);
//Add the ToolbarPalette to the ToolbarControl.
axToolbarControl1.AddItem(toolbarPalette, 0, - 1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
//Add commands to the ToolbarMenu.
}
Private Sub MapViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Add map inquiry commands
'Create a new ToolbarPalette.
Dim pToolbarPalette As IToolbarPalette = New ToolbarPaletteClass()
'Add commands and tools to the ToolbarPalette.
pToolbarPalette.AddItem("esriControls.ControlsNewMarkerTool", -1, -1)
pToolbarPalette.AddItem("esriControls.ControlsNewLineTool", -1, -1)
pToolbarPalette.AddItem("esriControls.ControlsNewCircleTool", -1, -1)
pToolbarPalette.AddItem("esriControls.ControlsNewEllipseTool", -1, -1)
pToolbarPalette.AddItem("esriControls.ControlsNewRectangleTool", -1, -1)
pToolbarPalette.AddItem("esriControls.ControlsNewPolygonTool", -1, -1)
'Add the ToolbarPalette to the ToolbarControl.
AxToolbarControl1.AddItem(pToolbarPalette, 0, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
'Add commands to the ToolbarMenu.
End Sub
private void MapViewer_Load(object sender, EventArgs e)
{
//Set label editing to manual.
axTOCControl1.LabelEdit = esriTOCControlEdit.esriTOCControlManual;
}
Private Sub MapViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Set label editing to manual.
AxTOCControl1.LabelEdit = esriTOCControlEdit.esriTOCControlManual
End Sub
private void axTOCControl1_OnEndLabelEdit(object sender,
ITOCControlEvents_OnEndLabelEditEvent e)
{
//If the new label is an empty string, prevent the edit.
if (e.newLabel.Trim() == "")
e.canEdit = false;
}
Private Sub AxTOCControl1_OnEndLabelEdit(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.ITOCControlEvents_OnEndLabelEditEvent) Handles AxTOCControl1.OnEndLabelEdit
'If the new label is an empty string, prevent the edit.
If e.newLabel.Trim = "" Then e.canEdit = False
End Sub
public partial class MapViewer: Form
{
//The envelope drawn on the MapControl.
private IEnvelope m_Envelope;
//The symbol used to draw the envelope on the MapControl.
private Object m_FillSymbol;
//The PageLayoutControl's focus map events.
private ITransformEvents_Event m_transformEvents;
private ITransformEvents_VisibleBoundsUpdatedEventHandler visBoundsUpdatedE;
}
Public Class MapViewer
'The envelope drawn on the MapControl.
Private m_pEnvelope As IEnvelope
'The symbol used to draw the envelope on the MapControl.
Private m_pFillSymbol As ISimpleFillSymbol
'The PageLayoutControl's focus map events.
Private m_pTransformEvents As ITransformEvents_Event
Private visBoundsUpdatedE As ITransformEvents_VisibleBoundsUpdatedEventHandler
End Class
private void CreateOverviewSymbol()
{
//Get the IRGBColor interface.
IRgbColor color = new RgbColorClass();
//Set the color properties.
color.RGB = 255;
//Get the ILine symbol interface.
ILineSymbol outline = new SimpleLineSymbolClass();
//Set the line symbol properties.
outline.Width = 1.5;
outline.Color = color;
//Get the IFillSymbol interface.
ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
//Set the fill symbol properties.
simpleFillSymbol.Outline = outline;
simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
m_FillSymbol = simpleFillSymbol;
}
Private Sub CreateOverviewSymbol()
'Get the IRGBColor interface.
Dim pColor As IRgbColor
pColor = New RgbColorClass
'Set the color properties.
pColor.RGB = RGB(255, 0, 0)
'Get the ILine symbol interface.
Dim pOutline As ILineSymbol
pOutline = New SimpleLineSymbolClass
'Set the line symbol properties.
pOutline.Width = 1.5
pOutline.Color = pColor
'Get the ISimpleFillSymbol interface.
m_pFillSymbol = New SimpleFillSymbolClass
'Set the fill symbol properties.
m_pFillSymbol.Outline = pOutline
m_pFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow
End Sub
private void MapViewer_Load(object sender, EventArgs e)
{
//Create the symbol used on the MapControl.
CreateOverviewSymbol();
}
Private Sub MapViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Create the symbol used on the MapControl.
CreateOverviewSymbol()
End Sub
private void OnVisibleBoundsUpdated(IDisplayTransformation sender, bool
sizeChanged)
{
//Set the extent to the new visible extent.
m_Envelope = sender.VisibleBounds;
//Refresh the MapControl's foreground phase.
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground,
null, null);
}
Private Sub OnVisibleBoundsUpdated(ByVal sender As IDisplayTransformation, ByVal sizeChanged As Boolean)
'Set the extent to the new visible extent.
m_pEnvelope = sender.VisibleBounds
'Refresh the MapControl's foreground phase.
AxMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, Nothing, Nothing)
End Sub
private void axPageLayoutControl1_OnPageLayoutReplaced(object sender,
IPageLayoutControlEvents_OnPageLayoutReplacedEvent e)
{
//Get the IActiveView of the focus map in the PageLayoutControl.
IActiveView activeView = axPageLayoutControl1.ActiveView.FocusMap as
IActiveView;
//Trap the ITranformEvents of the PageLayoutControl's focus map.
visBoundsUpdatedE = new ITransformEvents_VisibleBoundsUpdatedEventHandler
(OnVisibleBoundsUpdated);
IDisplayTransformation displayTransformation =
activeView.ScreenDisplay.DisplayTransformation;
//Start listening to the transform events interface.
m_transformEvents = (ITransformEvents_Event)displayTransformation;
//Start listening to the VisibleBoundsUpdated method on ITransformEvents interface.
m_transformEvents.VisibleBoundsUpdated += visBoundsUpdatedE;
//Get the extent of the focus map.
m_Envelope = activeView.Extent;
//Load the same pre-authored map document into the MapControl.
}
Private Sub AxPageLayoutControl1_OnPageLayoutReplaced(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnPageLayoutReplacedEvent) Handles AxPageLayoutControl1.OnPageLayoutReplaced
'Get the IActiveView of the focus map in the PageLayoutControl.
Dim activeView As IActiveView = AxPageLayoutControl1.ActiveView.FocusMap
'Trap the ITranformEvents of the PageLayoutControl's focus map.
visBoundsUpdatedE = New ITransformEvents_VisibleBoundsUpdatedEventHandler(AddressOf OnVisibleBoundsUpdated)
'Start listening to the transform events interface.
m_pTransformEvents = activeView.ScreenDisplay.DisplayTransformation
'Start listening to the VisibleBoundsUpdated method on ITransformEvents interface.
AddHandler (m_pTransformEvents.VisibleBoundsUpdated), visBoundsUpdatedE
'Get the extent of the focus map.
m_pEnvelope = activeView.Extent
'Load the same pre-authored map document into the MapControl.
End Sub
private void axMapControl1_OnAfterDraw(object sender,
IMapControlEvents2_OnAfterDrawEvent e)
{
if (m_Envelope == null)
return ;
//If the foreground phase has drawn.
esriViewDrawPhase viewDrawPhase = (esriViewDrawPhase)e.viewDrawPhase;
if (viewDrawPhase == esriViewDrawPhase.esriViewForeground)
{
IGeometry geometry = m_Envelope;
axMapControl1.DrawShape(geometry, ref m_FillSymbol);
}
}
Private Sub AxMapControl1_OnAfterDraw(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.IMapControlEvents2_OnAfterDrawEvent) Handles AxMapControl1.OnAfterDraw
If m_pEnvelope Is Nothing Then Exit Sub
'If the foreground phase has drawn.
Dim pViewDrawPhase As esriViewDrawPhase
pViewDrawPhase = e.viewDrawPhase
If pViewDrawPhase = esriViewDrawPhase.esriViewForeground Then
'Draw the shape on the MapControl
AxMapControl1.DrawShape(m_pEnvelope, m_pFillSymbol)
End If
End Sub
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.Geometry
public AddDateTool()
{
base.m_category = "CustomMapViewer";
base.m_caption = "Add Date";
base.m_message = "Adds a date element to the active view";
base.m_toolTip = "Add Date";
base.m_name = "CustomMapViewer_AddDateTool";
try
{
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
base.m_cursor = new Cursor(GetType(), GetType().Name + ".cur");
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}
Public Sub New()
MyBase.New()
MyBase.m_category = "CustomMapViewer"
MyBase.m_caption = "Add Date"
MyBase.m_message = "Adds a date element to the active view"
MyBase.m_toolTip = "Add Date"
MyBase.m_name = "CustomMapViewer_AddDateTool"
Try
Dim bitmapResourceName As String = Me.GetType().Name + ".bmp"
MyBase.m_bitmap = New Bitmap(Me.GetType(), bitmapResourceName)
MyBase.m_cursor = New Cursor(Me.GetType(), Me.GetType().Name + ".cur")
Catch ex As Exception
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap")
End Try
End Sub
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
//Get the active view.
IActiveView activeView = m_hookHelper.ActiveView;
//Create a new text element.
ITextElement textElement = new TextElementClass();
//Create a text symbol.
ITextSymbol textSymbol = new TextSymbolClass();
textSymbol.Size = 25;
//Set the text element properties.
textElement.Symbol = textSymbol;
textElement.Text = DateTime.Now.ToShortDateString();
//Query interface (QI) for IElement.
IElement element = (IElement)textElement;
//Create a point.
IPoint point = new PointClass();
point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
//Set the element's geometry.
element.Geometry = point;
//Add the element to the graphics container.
activeView.GraphicsContainer.AddElement(element, 0);
//Refresh the graphics.
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
Public Overrides Sub OnMouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Integer, ByVal Y As Integer)
'Get the active view.
Dim pActiveView As IActiveView = m_hookHelper.ActiveView
'Create a new text element.
Dim pTextElement As ITextElement = New TextElementClass
'Create a text symbol.
Dim pTextSymbol As ITextSymbol = New TextSymbolClass
pTextSymbol.Size = 25
'Set the text element properties.
pTextElement.Symbol = pTextSymbol
pTextElement.Text = Date.Now.ToShortDateString
'Query interface (QI) for IElement.
Dim pElement As IElement
pElement = pTextElement
'Create a point.
Dim pPoint As IPoint
pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y)
'Set the element's geometry.
pElement.Geometry = pPoint
'Add the element to the graphics container.
pActiveView.GraphicsContainer.AddElement(pTextElement, 0)
'Refresh the graphics.
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, Nothing, Nothing)
End Sub
private void MapViewer_Load(object sender, EventArgs e)
{
//Add map inquiry commands.
//Add custom AddDateTool.
axToolbarControl1.AddItem("Commands.AddDateTool", - 1, - 1, false, 0,
esriCommandStyles.esriCommandStyleIconAndText);
//Create a new ToolbarPalette.
}
Private Sub MapViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Add map inquiry commands.
'Add custom AddDateTool.
AxToolbarControl1.AddItem("Commands.AddDateTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconAndText)
'Create a new ToolbarPalette.
End Sub
public partial class MapViewer: Form
{
//The CustomizeDialog used by the ToolbarControl.
private ICustomizeDialog m_CustomizeDialog;
//The CustomizeDialog start event.
private ICustomizeDialogEvents_OnStartDialogEventHandler startDialogE;
//The CustomizeDialog close event.
private ICustomizeDialogEvents_OnCloseDialogEventHandler closeDialogE;
}
Public Class MapViewer
'The CustomizeDialog used by the ToolbarControl.
Private m_pCustomizeDialog As ICustomizeDialog
'The CustomizeDialog start event.
Private startDialogE As ICustomizeDialogEvents_OnStartDialogEventHandler
'The CustomizeDialog close event.
Private closeDialogE As ICustomizeDialogEvents_OnCloseDialogEventHandler
End Class
private void CreateCustomizeDialog()
{
//Create a new Customize dialog box.
m_CustomizeDialog = new CustomizeDialogClass();
//Set the title.
m_CustomizeDialog.DialogTitle = "Customize ToolbarControl Items";
//Show the Add from File button.
m_CustomizeDialog.ShowAddFromFile = true;
//Set the ToolbarControl that new items will be added to.
m_CustomizeDialog.SetDoubleClickDestination(axToolbarControl1);
//Set the Customize dialog box events.
startDialogE = new ICustomizeDialogEvents_OnStartDialogEventHandler
(OnStartDialog);
((ICustomizeDialogEvents_Event)m_CustomizeDialog).OnStartDialog +=
startDialogE;
closeDialogE = new ICustomizeDialogEvents_OnCloseDialogEventHandler
(OnCloseDialog);
((ICustomizeDialogEvents_Event)m_CustomizeDialog).OnCloseDialog +=
closeDialogE;
}
Private Sub CreateCustomizeDialog()
'Create a new Customize dialog box.
m_pCustomizeDialog = New CustomizeDialogClass()
'Set the title.
m_pCustomizeDialog.DialogTitle = "Customize ToolbarControl Items"
'Show the Add from File button.
m_pCustomizeDialog.ShowAddFromFile = True
'Set the ToolbarControl that new items will be added to.
m_pCustomizeDialog.SetDoubleClickDestination(AxToolbarControl1)
'Set the Customize dialog box events.
startDialogE = New ICustomizeDialogEvents_OnStartDialogEventHandler(AddressOf OnStartDialog)
AddHandler CType(m_pCustomizeDialog, ICustomizeDialogEvents_Event).OnStartDialog, startDialogE
closeDialogE = New ICustomizeDialogEvents_OnCloseDialogEventHandler(AddressOf OnCloseDialog)
AddHandler CType(m_pCustomizeDialog, ICustomizeDialogEvents_Event).OnCloseDialog, closeDialogE
End Sub
private void MapViewer_Load(object sender, EventArgs e)
{
//Create the Customize dialog box for the ToolbarControl.
CreateCustomizeDialog();
//Create the symbol used on the MapControl.
}
Private Sub MapViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Create the Customize dialog box for the ToolbarControl.
CreateCustomizeDialog()
'Create the symbol used on the MapControl.
End Sub
private void chkCustomize_CheckedChanged(object sender, EventArgs e)
{
//Show or hide the Customize dialog box.
if (chkCustomize.Checked == false)
m_CustomizeDialog.CloseDialog();
else
m_CustomizeDialog.StartDialog(axToolbarControl1.hWnd);
}
Private Sub chkCustomize_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCustomize.CheckedChanged
'Show or hide the Customize dialog box.
If chkCustomize.Checked = False Then
m_pCustomizeDialog.CloseDialog()
Else
m_pCustomizeDialog.StartDialog(AxToolbarControl1.hWnd)
End If
End Sub
private void OnStartDialog()
{
axToolbarControl1.Customize = true;
}
private void OnCloseDialog()
{
axToolbarControl1.Customize = false;
chkCustomize.Checked = false;
}
Private Sub OnStartDialog()
AxToolbarControl1.Customize = True
End Sub
Private Sub OnCloseDialog()
AxToolbarControl1.Customize = False
chkCustomize.Checked = False
End Sub
private void SaveToolbarControlItems(string filePath)
{
//Create a MemoryBlobStream.
IBlobStream blobStream = new MemoryBlobStreamClass();
//Get the IStream interface.
IStream stream = blobStream;
//Save the ToolbarControl into the stream.
axToolbarControl1.SaveItems(stream);
//Save the stream to a file.
blobStream.SaveToFile(filePath);
}
Private Sub SaveToolbarControlItems(ByVal filePath)
'Create a MemoryBlobStream.
Dim blobStream As IBlobStream
blobStream = New MemoryBlobStreamClass
'Get the IStream interface.
Dim stream As IStream
stream = blobStream
'Save the ToolbarControl into the stream.
AxToolbarControl1.SaveItems(stream)
'Save the stream to a file.
blobStream.SaveToFile(filePath)
End Sub
private void LoadToolbarControlItems(string filePath)
{
//Create a MemoryBlobStream.
IBlobStream blobStream = new MemoryBlobStreamClass();
//Get the IStream interface.
IStream stream = blobStream;
//Load the stream from the file.
blobStream.LoadFromFile(filePath);
//Load the stream into the ToolbarControl.
axToolbarControl1.LoadItems(stream);
}
Private Sub LoadToolbarControlItems(ByVal filePath)
'Create a MemoryBlobStream.
Dim blobStream As IBlobStream
blobStream = New MemoryBlobStreamClass
'Get the IStream interface.
Dim stream As IStream
stream = blobStream
'Load the stream from the file.
blobStream.LoadFromFile(filePath)
'Load the stream into the ToolbarControl.
AxToolbarControl1.LoadItems(stream)
End Sub
private void MapViewer_FormClosing(object sender, FormClosingEventArgs e)
{
//Get file name to persist the ToolbarControl.
String filePath = System.Reflection.Assembly.GetExecutingAssembly()
.Location.Replace("Controls.exe", "") + @"\PersistedItems.txt";
//Persist ToolbarControl contents.
SaveToolbarControlItems(filePath);
}
Private Sub MapViewer_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
'Get file name to persist the ToolbarControl.
Dim filePath As String
filePath = System.Reflection.Assembly.GetExecutingAssembly.Location.Replace("Controls.exe", "") & "\PersistedItems.txt"
'Persist ToolbarControl contents.
SaveToolbarControlItems(filePath)
End Sub
//Get file name used to persist the ToolbarControl.
String filePath = System.Reflection.Assembly.GetExecutingAssembly()
.Location.Replace("Controls.exe", "") + @"\PersistedItems.txt";
if (System.IO.File.Exists(filePath))
LoadToolbarControlItems(filePath);
else
{
//Add generic commands.
axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsAddDataCommand", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//Add page layout navigation commands.
axToolbarControl1.AddItem("esriControls.ControlsPageZoomInTool", - 1, - 1,
true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsPageZoomOutTool", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsPagePanTool", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsPageZoomWholePageCommand", -
1, - 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//Add map navigation commands.
axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", - 1, - 1,
true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapPanTool", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", - 1,
- 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem(
"esriControls.ControlsMapZoomToLastExtentBackCommand", - 1, - 1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem(
"esriControls.ControlsMapZoomToLastExtentForwardCommand", - 1, - 1, false,
0, esriCommandStyles.esriCommandStyleIconOnly);
//Add map inquiry commands.
axToolbarControl1.AddItem("esriControls.ControlsMapIdentifyTool", - 1, - 1,
true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapFindCommand", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapMeasureTool", - 1, - 1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//Add custom AddDateTool.
axToolbarControl1.AddItem("Commands.AddDateTool", - 1, - 1, false, 0,
esriCommandStyles.esriCommandStyleIconAndText);
//Create a new ToolbarPalette.
IToolbarPalette toolbarPalette = new ToolbarPaletteClass();
//Add commands and tools to the ToolbarPalette.
toolbarPalette.AddItem("esriControls.ControlsNewMarkerTool", - 1, - 1);
toolbarPalette.AddItem("esriControls.ControlsNewLineTool", - 1, - 1);
toolbarPalette.AddItem("esriControls.ControlsNewCircleTool", - 1, - 1);
toolbarPalette.AddItem("esriControls.ControlsNewEllipseTool", - 1, - 1);
toolbarPalette.AddItem("esriControls.ControlsNewRectangleTool", - 1, - 1);
toolbarPalette.AddItem("esriControls.ControlsNewPolygonTool", - 1, - 1);
//Add the ToolbarPalette to the ToolbarControl.
axToolbarControl1.AddItem(toolbarPalette, 0, - 1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
}
'Get file name used to persist the ToolbarControl.
Dim filePath As String
filePath = System.Reflection.Assembly.GetExecutingAssembly.Location.Replace("Controls.exe", "") & "\PersistedItems.txt"
If System.IO.File.Exists(filePath) Then
LoadToolbarControlItems(filePath)
Else
'Add generic commands.
AxToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsAddDataCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
'Add page layout navigation commands.
AxToolbarControl1.AddItem("esriControls.ControlsPageZoomInTool", -1, -1, True, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsPageZoomOutTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsPagePanTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsPageZoomWholePageCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
'Add map navigation commands.
AxToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", -1, -1, True, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapPanTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentBackCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentForwardCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
'Add map inquiry commands.
AxToolbarControl1.AddItem("esriControls.ControlsMapIdentifyTool", -1, -1, True, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapFindCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
AxToolbarControl1.AddItem("esriControls.ControlsMapMeasureTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
'Add custom AddDateTool.
AxToolbarControl1.AddItem("Commands.AddDateTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconAndText)
'Create a new ToolbarPalette.
Dim pToolbarPalette As IToolbarPalette = New ToolbarPaletteClass()
'Add commands and tools to the ToolbarPalette.
pToolbarPalette.AddItem("esriControls.ControlsNewMarkerTool", -1, -1)
pToolbarPalette.AddItem("esriControls.ControlsNewLineTool", -1, -1)
pToolbarPalette.AddItem("esriControls.ControlsNewCircleTool", -1, -1)
pToolbarPalette.AddItem("esriControls.ControlsNewEllipseTool", -1, -1)
pToolbarPalette.AddItem("esriControls.ControlsNewRectangleTool", -1, -1)
pToolbarPalette.AddItem("esriControls.ControlsNewPolygonTool", -1, -1)
'Add the ToolbarPalette to the ToolbarControl.
AxToolbarControl1.AddItem(pToolbarPalette, 0, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
End If
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
//Exit if there is no system default printer.
if (axPageLayoutControl1.Printer == null)
{
MessageBox.Show("Unable to print!", "No default printer");
return ;
}
//Set printer papers orientation to that of the page.
axPageLayoutControl1.Printer.Paper.Orientation =
axPageLayoutControl1.Page.Orientation;
//Scale to the page.
axPageLayoutControl1.Page.PageToPrinterMapping =
esriPageToPrinterMapping.esriPageMappingScale;
//Send the page layout to the printer.
axPageLayoutControl1.PrintPageLayout();
}
Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
'Exit if there is no system default printer.
If AxPageLayoutControl1.Printer Is Nothing Then
MessageBox.Show("Unable to print!", "No default printer")
Exit Sub
End If
'Set printer papers orientation to that of the page.
AxPageLayoutControl1.Printer.Paper.Orientation = AxPageLayoutControl1.Page.Orientation
'Scale to the page.
AxPageLayoutControl1.Page.PageToPrinterMapping = esriPageToPrinterMapping.esriPageMappingScale
'Send the page layout to the printer.
AxPageLayoutControl1.PrintPageLayout()
End Sub