ArcObjects Library Reference  

ScaleThresholds

About the Displaying a TOCControl context menu Sample

[C#]

ScaleThresholds.cs

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

namespace ContextMenu
{
	public class ScaleThresholds : BaseCommand, ICommandSubType
	{
		private IMapControl3 m_mapControl;
		private long m_subType;

		public ScaleThresholds()
		{

		}
	
		public override void OnClick()
		{
			ILayer layer = (ILayer) m_mapControl.CustomProperty;
			if (m_subType == 1) layer.MaximumScale = m_mapControl.MapScale;
			if (m_subType == 2) layer.MinimumScale = m_mapControl.MapScale;
			if (m_subType == 3)
			{
				layer.MaximumScale = 0;
				layer.MinimumScale = 0;
			}
			m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography,null,null);
		}
	
		public override void OnCreate(object hook)
		{
			m_mapControl = (IMapControl3) hook;
		}
	
		public int GetCount()
		{
			return 3;
		}
	
		public void SetSubType(int SubType)
		{
			m_subType = SubType;
		}
	
		public override string Caption
		{
			get
			{
				if (m_subType == 1) return "Set Maximum Scale";
				else if (m_subType == 2) return "Set Minimum Scale";
				else return "Remove Scale Thresholds";
			}
		}
	
		public override bool Enabled
		{
			get
			{
				bool enabled = true;
				ILayer layer = (ILayer) m_mapControl.CustomProperty;
				
				if (m_subType == 3)
				{
					if ((layer.MaximumScale == 0) & (layer.MinimumScale == 0)) enabled = false;
				}
				return enabled;
			}
		}
	}
}


[Visual Basic .NET]

ScaleThresholds.vb

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

Public NotInheritable Class ScaleThresholds

    Inherits BaseCommand
    Implements ICommandSubType

    Private m_pMapControl As IMapControl3
    Private m_lSubType As Long

    Public Sub New()
        MyBase.New()
    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
        If (m_lSubType = 1) Then pLayer.MaximumScale = m_pMapControl.MapScale
        If (m_lSubType = 2) Then pLayer.MinimumScale = m_pMapControl.MapScale
        If (m_lSubType = 3) Then
            pLayer.MaximumScale = 0
            pLayer.MinimumScale = 0
        End If
        m_pMapControl.Refresh(esriViewDrawPhase.esriViewGeography)
    End Sub

    Public Function GetCount() As Integer Implements ESRI.ArcGIS.SystemUI.ICommandSubType.GetCount
        Return 3
    End Function

    Public Sub SetSubType(ByVal SubType As Integer) Implements ESRI.ArcGIS.SystemUI.ICommandSubType.SetSubType
        m_lSubType = SubType
    End Sub

    Public Overrides ReadOnly Property Caption() As String
        Get
            If (m_lSubType = 1) Then
                Return "Set Maximum Scale"
            ElseIf (m_lSubType = 2) Then
                Return "Set Minimum Scale"
            Else
                Return "Remove Scale Thresholds"
            End If
        End Get
    End Property

    Public Overrides ReadOnly Property Enabled() As Boolean
        Get
            Dim bEnabled As Boolean
            bEnabled = True

            Dim pLayer As ILayer
            pLayer = m_pMapControl.CustomProperty

            If (m_lSubType = 3) Then
                If (pLayer.MaximumScale = 0) And (pLayer.MinimumScale = 0) Then bEnabled = False
            End If
            Return bEnabled
        End Get
    End Property
End Class