ArcObjects Library Reference  

MultivariateRendPropPage

About the Multivariate renderer Sample

[C#]

MultivariateRendPropPage.cs


using System;
using System.Collections;
using System.Data;
using System.Diagnostics;

using System.Drawing;
using System.Runtime.InteropServices;

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.CartoUI;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;

namespace MultivariateRenderers
{
    [Guid("FE338F20-B39C-49B8-9F28-FAC2F0DE0C0D")]
    [ClassInterface(ClassInterfaceType.None)]
    [ComVisible(true)]
    [ProgId("MultiVariateRenderers.MultivariateRendPropPageCS")]
	public class MultivariateRendPropPageCS : IComPropertyPage, IComEmbeddedPropertyPage, IRendererPropertyPage
	{
		// custom renderer property page class for MultivariateRenderer

		// a renderer property page must implement these interfaces:

		[DllImport("gdi32.dll")]
		private extern static bool DeleteObject(IntPtr hObject);

		private PropPageForm m_Page;
		private IFeatureRenderer m_pRend;
		private long m_Priority;
		private System.Drawing.Bitmap m_bitmap;
		private IntPtr m_hBitmap;


		public MultivariateRendPropPageCS()
		{
			//'MsgBox("New (color prop page)")
			m_Page = new PropPageForm();
			m_Priority = 550; // 5th category is for multiple attribute renderers

			string[] res = typeof(MultivariateRendPropPageCS).Assembly.GetManifestResourceNames();
			if (res.GetLength(0) > 0)
			{
				
                

                try
                {   
                    string bitmapResourceName = GetType().Name + ".bmp";
                    //creating a new bitmap
                    m_bitmap = new Bitmap(GetType(), bitmapResourceName);
                }
                 catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
                }


				if (m_bitmap != null)
				{
					m_bitmap.MakeTransparent(m_bitmap.GetPixel(1, 1));
					m_hBitmap = m_bitmap.GetHbitmap();
				}
			}

		}

		~MultivariateRendPropPageCS()
		{
			if (m_hBitmap.ToInt32() != 0)
				DeleteObject(m_hBitmap);
		}


	#region Component Category Registration
		[ComRegisterFunction()]
		public static void Reg(string regKey)
		{
			RendererPropertyPages.Register(regKey);
		}

		[ComUnregisterFunction()]
		public static void Unreg(string regKey)
		{
			RendererPropertyPages.Unregister(regKey);
		}
	#endregion

		public int Activate()
		{

			return m_Page.Handle.ToInt32();

		}

		public bool Applies(ESRI.ArcGIS.esriSystem.ISet objects)
		{

			object pObj = null;

			if (objects.Count <= 0)
			{
				return false;
				return false;
			}

			objects.Reset();
			pObj = objects.Next();
			while (! (pObj is IFeatureRenderer))
			{
				pObj = objects.Next();
				if (pObj == null)
				{
					return false;
					return false;
				}
			}

			return (pObj is IMultivariateRenderer);

		}

		public void Apply()
		{
			QueryObject(m_pRend);

		}

		public void Cancel()
		{
			// doing nothing discards any changes made on the page since last Apply.  this is
			//   what we want.

		}

		public void Deactivate()
		{
			// Unload m_Page in VB6

		}

		public int Height
		{
			get
			{
				//MsgBox("Height")
				return m_Page.Height;
			}
		}

		public int get_HelpContextID(int controlID)
		{
		return 0;
		}

		public string HelpFile
		{
			get
			{
			return null;
			}
		}

		public void Hide()
		{
			m_Page.Hide();
			

		}

		public bool IsPageDirty
		{
			get
			{
				// check flag on form to see if page is dirty
				// this tells the property sheet whether or not to redraw page
				return m_Page.IsDirty;
			}
		}

		public IComPropertyPageSite PageSite
		{
			set
			{
				m_Page.PageSite = value;
			}
		}

		public int Priority
		{
			get
			{
				return (int)m_Priority;
			}
			set
			{
				m_Priority = value;
			}
		}

		public void SetObjects(ESRI.ArcGIS.esriSystem.ISet objects)
		{
			// supplies the page with the object(s) to be edited including the map, feature layer,
			//   feature class, and renderer
			// note:  the feature renderer passed in as part of Objects is the one created
			//   in CreateCompatibleObject

			object pObj = null;

			if (objects.Count <= 0)
				return;
			objects.Reset();
			pObj = objects.Next();

			IMap pMap = null;
			IGeoFeatureLayer pGeoLayer = null;

			// in this implementation we need info from the map and the renderer
			while (pObj != null)
			{
				if (pObj is IMap)
						pMap = pObj as IMap;
				if (pObj is IGeoFeatureLayer)
						pGeoLayer = pObj as IGeoFeatureLayer;
				if (pObj is IFeatureRenderer)
						m_pRend = pObj as IFeatureRenderer;

				pObj = objects.Next();
			}
			if ((pMap != null) & (pGeoLayer != null) & (m_pRend != null))
			{
				m_Page.InitControls(m_pRend as IMultivariateRenderer, pMap, pGeoLayer);
			}

		}

		public void Show()
		{
			m_Page.Show();

		}

		public string Title
		{
			get
			{
				return m_Page.Name;
			}
			set
			{
				m_Page.Name = value;
			}
		}

		public int Width
		{
			get
			{
				return m_Page.Width;
			}
		}

		public object CreateCompatibleObject(object kind)
		{
			// check to see if the renderer is compatible with the property page...
			//    ...if so, return the renderer.  If not, create a new one.

			IFeatureRenderer pFeatRend = null;

			if ((kind is IMultivariateRenderer) & (kind != null))
				pFeatRend = kind as IFeatureRenderer;
			else
			{
				// create a new MultivariateRenderer 
				pFeatRend = new MultivariateRenderer();
			}

			return pFeatRend;
		}

		public void QueryObject(object theObject)
		{
			// triggered when OK or Apply is pressed on the property page
			IFeatureRenderer pRend = null;

			if ((theObject is IMultivariateRenderer) & (theObject != null))
			{
				pRend = theObject as IFeatureRenderer;
				m_Page.InitRenderer(pRend as IMultivariateRenderer);
			}
		}

		public bool CanEdit(IFeatureRenderer obj)
		{
			return (obj is IMultivariateRenderer);

		}

		ESRI.ArcGIS.esriSystem.UID IRendererPropertyPage.ClassID
		{
			get
			{
				return ClassID1;
			}
		}
		public ESRI.ArcGIS.esriSystem.UID ClassID1
		{
			get
			{
				// return prog id of the property page object
				UID pUID = new UID();
				pUID.Value = "MultivariateRenderers.MultivariateRendPropPageCS";
				return pUID;
			}
		}

		public string Description
		{
			get
			{
				// appears on ArcMap symbology property page
				return "Display features with multivariate symbology";
			}
		}

		public string Name
		{
			get
			{
				return "Multivariate Renderer CS";
			}
		}

		public int PreviewImage
		{
			get
			{
				return m_hBitmap.ToInt32();
			}
		}

		public ESRI.ArcGIS.esriSystem.UID RendererClassID
		{
			get
			{
				UID pUID = new UID();
				pUID.Value = "MultivariateRenderers.MultivariateRendererCS";
				return pUID;
			}
		}

		public string Type
		{
			get
			{
				// text that appears for category in "Show" tree view
				//   on symbology property page

				return "Multiple Attributes";
			}
		}
	}



} //end of root namespace
[Visual Basic .NET]

MultivariateRendPropPage.vb

Imports System.Drawing
Imports System.Runtime.InteropServices

Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.CartoUI
Imports ESRI.ArcGIS.Framework
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.ADF.BaseClasses
Imports ESRI.ArcGIS.ADF.CATIDs

<ComClass(MultivariateRendPropPage.ClassId, MultivariateRendPropPage.InterfaceId, MultivariateRendPropPage.EventsId)> _
Public Class MultivariateRendPropPage
    ' custom renderer property page class for MultivariateRenderer

    ' a renderer property page must implement these interfaces:
    Implements IComPropertyPage
    Implements IComEmbeddedPropertyPage
    Implements IRendererPropertyPage

    <DllImport("gdi32.dll")> _
    Private Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean
    End Function

    Private m_Page As PropPageForm
    Private m_pRend As IFeatureRenderer
    Private m_Priority As Long
    Private m_bitmap As System.Drawing.Bitmap
    Private m_hBitmap As IntPtr


    Public Sub New()
        ''MsgBox("New (color prop page)")
        m_Page = New PropPageForm
        m_Priority = 550    ' 5th category is for multiple attribute renderers

        Dim res() As String = GetType(MultivariateRendPropPage).Assembly.GetManifestResourceNames()
        If (res.GetLength(0) > 0) Then
            Try

                Dim bitmapResourceName As String = Me.GetType().Name + ".bmp"
                m_bitmap = New System.Drawing.Bitmap(Me.GetType().Assembly.GetManifestResourceStream(bitmapResourceName))
                If Not (m_bitmap Is Nothing) Then
                    m_bitmap.MakeTransparent(m_bitmap.GetPixel(1, 1))
                    m_hBitmap = m_bitmap.GetHbitmap()
                End If
            Catch

            End Try

        End If

    End Sub

    Protected Overrides Sub Finalize()
        If (m_hBitmap.ToInt32() <> 0) Then
            DeleteObject(m_hBitmap)
        End If
    End Sub

#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class 
    ' and its COM interfaces. If you change them, existing 
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "FE338F20-B39C-49B8-9F28-FAC2F0DE0C0D"
    Public Const InterfaceId As String = "BAC02C70-EC55-4A1D-AF09-08E39BEA78DB"
    Public Const EventsId As String = "AED3C901-6B05-40A9-93CF-FE26C6C3FA01"
#End Region

#Region "Component Category Registration"
    <ComRegisterFunction()> _
    Public Shared Sub Reg(ByVal regKey As String)
        RendererPropertyPages.Register(regKey)
    End Sub

    <ComUnregisterFunction()> _
    Public Shared Sub Unreg(ByVal regKey As String)
        RendererPropertyPages.Unregister(regKey)
    End Sub
#End Region

    Public Function Activate() As Integer Implements IComPropertyPage.Activate

        Return m_Page.Handle.ToInt32()

    End Function

    Public Function Applies(ByVal objects As ESRI.ArcGIS.esriSystem.ISet) As Boolean Implements IComPropertyPage.Applies

        Dim pObj As Object

        If objects.Count <= 0 Then
            Return False
            Exit Function
        End If

        objects.Reset()
        pObj = objects.Next
        Do While Not TypeOf pObj Is IFeatureRenderer
            pObj = objects.Next
            If pObj Is Nothing Then
                Return False
                Exit Function
            End If
        Loop

        Return (TypeOf pObj Is IMultivariateRenderer)

    End Function

    Public Sub Apply() Implements IComPropertyPage.Apply
        QueryObject(m_pRend)

    End Sub

    Public Sub Cancel() Implements IComPropertyPage.Cancel
        ' doing nothing discards any changes made on the page since last Apply.  this is
        '   what we want.

    End Sub

    Public Sub Deactivate() Implements IComPropertyPage.Deactivate

    End Sub

    Public ReadOnly Property Height() As Integer Implements IComPropertyPage.Height
        Get
            'MsgBox("Height")
            Return m_Page.Height
        End Get
    End Property

    Public ReadOnly Property HelpContextID(ByVal controlID As Integer) As Integer Implements IComPropertyPage.HelpContextID
        Get
            ' NOTIMPL
        End Get
    End Property

    Public ReadOnly Property HelpFile() As String Implements IComPropertyPage.HelpFile
        Get
            Return ""
        End Get
    End Property

    Public Sub Hide() Implements IComPropertyPage.Hide
        m_Page.Hide()

    End Sub

    Public ReadOnly Property IsPageDirty() As Boolean Implements IComPropertyPage.IsPageDirty
        Get
            ' check flag on form to see if page is dirty
            ' this tells the property sheet whether or not to redraw page
            Return m_Page.IsDirty
        End Get
    End Property

    Public WriteOnly Property PageSite() As IComPropertyPageSite Implements IComPropertyPage.PageSite
        Set(ByVal Value As IComPropertyPageSite)
            m_Page.PageSite = Value
        End Set
    End Property

    Public Property Priority() As Integer Implements IComPropertyPage.Priority
        Get
            Return m_Priority
        End Get
        Set(ByVal Value As Integer)
            m_Priority = Value
        End Set
    End Property

    Public Sub SetObjects(ByVal objects As ESRI.ArcGIS.esriSystem.ISet) Implements IComPropertyPage.SetObjects
        ' supplies the page with the object(s) to be edited including the map, feature layer,
        '   feature class, and renderer
        ' note:  the feature renderer passed in as part of Objects is the one created
        '   in CreateCompatibleObject

        Dim pObj As Object

        If objects.Count <= 0 Then
            Exit Sub
        End If
        objects.Reset()
        pObj = objects.Next

        Dim pMap As IMap = Nothing
        Dim pGeoLayer As IGeoFeatureLayer = Nothing

        ' in this implementation we need info from the map and the renderer
        Do While Not pObj Is Nothing
            If TypeOf pObj Is IMap Then pMap = pObj
            If TypeOf pObj Is IGeoFeatureLayer Then pGeoLayer = pObj
            If TypeOf pObj Is IFeatureRenderer Then m_pRend = pObj

            pObj = objects.Next
        Loop
        If (Not pMap Is Nothing) And (Not pGeoLayer Is Nothing) And (Not m_pRend Is Nothing) Then
            m_Page.InitControls(m_pRend, pMap, pGeoLayer)
        End If

    End Sub

    Public Sub Show() Implements IComPropertyPage.Show
        m_Page.Show()

    End Sub

    Public Property Title() As String Implements IComPropertyPage.Title
        Get
            Return m_Page.Name
        End Get
        Set(ByVal Value As String)
            m_Page.Name = Value
        End Set
    End Property

    Public ReadOnly Property Width() As Integer Implements IComPropertyPage.Width
        Get
            Return m_Page.Width
        End Get
    End Property

    Public Function CreateCompatibleObject(ByVal kind As Object) As Object Implements IComEmbeddedPropertyPage.CreateCompatibleObject
        ' check to see if the renderer is compatible with the property page...
        '    ...if so, return the renderer.  If not, create a new one.

        Dim pFeatRend As IFeatureRenderer

        If (TypeOf kind Is IMultivariateRenderer) And (Not kind Is Nothing) Then
            pFeatRend = kind
        Else
            ' create a new MultivariateRenderer 
            pFeatRend = New MultivariateRenderer
        End If

        Return pFeatRend
    End Function

    Public Sub QueryObject(ByVal theObject As Object) Implements IComEmbeddedPropertyPage.QueryObject
        ' triggered when OK or Apply is pressed on the property page
        Dim pRend As IFeatureRenderer

        If (TypeOf theObject Is IMultivariateRenderer) And (Not theObject Is Nothing) Then
            pRend = theObject
            m_Page.InitRenderer(pRend)
        End If
    End Sub

    Public Function CanEdit(ByVal obj As IFeatureRenderer) As Boolean Implements IRendererPropertyPage.CanEdit
        Return (TypeOf obj Is IMultivariateRenderer)

    End Function

    Public ReadOnly Property ClassID1() As ESRI.ArcGIS.esriSystem.UID Implements IRendererPropertyPage.ClassID
        Get
            ' return prog id of the property page object
            Dim pUID As New UID
            pUID.Value = "MultivariateRendPropPage"
            Return pUID
        End Get
    End Property

    Public ReadOnly Property Description() As String Implements IRendererPropertyPage.Description
        Get
            ' appears on ArcMap symbology property page
            Return "Display features with multivariate symbology"
        End Get
    End Property

    Public ReadOnly Property Name() As String Implements IRendererPropertyPage.Name
        Get
            Return "Multivariate Renderer"
        End Get
    End Property

    Public ReadOnly Property PreviewImage() As Integer Implements IRendererPropertyPage.PreviewImage
        Get
            Return m_hBitmap.ToInt32()
        End Get
    End Property

    Public ReadOnly Property RendererClassID() As ESRI.ArcGIS.esriSystem.UID Implements IRendererPropertyPage.RendererClassID
        Get
            Dim pUID As New UID
            pUID.Value = "MultivariateRenderer"
            Return pUID
        End Get
    End Property

    Public ReadOnly Property Type() As String Implements IRendererPropertyPage.Type
        Get
            ' text that appears for category in "Show" tree view
            '   on symbology property page

            Return "Multiple Attributes"
        End Get
    End Property
End Class