ArcObjects Library Reference  

cmdRemoveLayer

About the Network Analyst Engine application Sample

[C#]

cmdRemoveLayer.cs

using System.Windows.Forms;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;

// This command removes the selected layer from the map

namespace NAEngine
{
	[Guid("53399A29-2B65-48d5-930F-804B88B85A34")]
	[ClassInterface(ClassInterfaceType.None)]
	[ProgId("NAEngine.RemoveLayer")]
	public sealed class cmdRemoveLayer : BaseCommand
	{
		private IMapControl3 m_mapControl;

		public cmdRemoveLayer()
		{
			base.m_caption = "Remove Layer";
		}

		public override void OnClick()
		{
			// Get the NALayer that was right-clicked on in the table of contents
			// m_MapControl.CustomProperty was set in frmMain.axTOCControl1_OnMouseDown
			ILayer layer = (ILayer)m_mapControl.CustomProperty;
			m_mapControl.Map.DeleteLayer(layer);
			m_mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, layer.AreaOfInterest);
		}

		public override void OnCreate(object hook)
		{
			m_mapControl = (IMapControl3)hook;
		}
	}
}

[Visual Basic .NET]

cmdRemoveLayer.vb

Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports ESRI.ArcGIS.ADF.BaseClasses
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Controls

' This command removes the selected layer from the map

Namespace NAEngine
	<Guid("E9376DA6-E403-46c7-86B5-6A4A6C818BA0"), ClassInterface(ClassInterfaceType.None), ProgId("NAEngine.RemoveLayer")> _
 Public NotInheritable Class RemoveLayer : Inherits BaseCommand
		Private m_mapControl As IMapControl3

		Public Sub New()
			MyBase.m_caption = "Remove Layer"
		End Sub

		Public Overloads Overrides Sub OnClick()
			' Get the NALayer that was right-clicked on in the table of contents
			' m_MapControl.CustomProperty was set in frmMain.axTOCControl1_OnMouseDown
			Dim layer As ILayer = CType(m_mapControl.CustomProperty, ILayer)
            m_mapControl.Map.DeleteLayer(layer)
            m_mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, Nothing, layer.AreaOfInterest)
		End Sub

		Public Overloads Overrides Sub OnCreate(ByVal hook As Object)
			m_mapControl = CType(hook, IMapControl3)
		End Sub
	End Class
End Namespace