ArcObjects Library Reference  

RemoveLayer

About the Displaying a TOCControl context menu Sample

[C#]

RemoveLayer.cs

using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;

namespace ContextMenu
{
	public sealed class RemoveLayer : BaseCommand  
	{
		private IMapControl3 m_mapControl;

		public RemoveLayer()
		{
			base.m_caption = "Remove Layer";
		}
	
		public override void OnClick()
		{
			ILayer layer =  (ILayer) m_mapControl.CustomProperty;
			m_mapControl.Map.DeleteLayer(layer);
		}
	
		public override void OnCreate(object hook)
		{
			m_mapControl = (IMapControl3) hook;
		}

	}
}



[Visual Basic .NET]

RemoveLayer.vb

Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Controls
Imports ESRI.ArcGIS.ADF.BaseClasses

Public NotInheritable Class RemoveLayer

    Inherits BaseCommand

    Private m_pMapControl As IMapControl3

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

    Public Overrides Sub OnCreate(ByVal hook As Object)
        m_pMapControl = hook
    End Sub

    Public Overrides Sub OnClick()
        Dim pLayer As ILayer
        pLayer = m_pMapControl.CustomProperty
        m_pMapControl.Map.DeleteLayer(pLayer)
    End Sub
End Class