About the Change layer rendering using the SymbologyControl Sample
[C#]
LayerRendering.cs
using System; using System.Windows.Forms; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.SystemUI; using ESRI.ArcGIS; namespace LayerRendering { public class Form1 : System.Windows.Forms.Form { public System.Windows.Forms.Label Label1; public System.Windows.Forms.Label Label2; private ESRI.ArcGIS.Controls.AxToolbarControl axToolbarControl1; private ESRI.ArcGIS.Controls.AxTOCControl axTOCControl1; private ESRI.ArcGIS.Controls.AxPageLayoutControl axPageLayoutControl1; private ESRI.ArcGIS.Controls.AxLicenseControl axLicenseControl1; private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { //Release COM objects ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown(); if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.Label1 = new System.Windows.Forms.Label(); this.Label2 = new System.Windows.Forms.Label(); this.axToolbarControl1 = new ESRI.ArcGIS.Controls.AxToolbarControl(); this.axTOCControl1 = new ESRI.ArcGIS.Controls.AxTOCControl(); this.axPageLayoutControl1 = new ESRI.ArcGIS.Controls.AxPageLayoutControl(); this.axLicenseControl1 = new ESRI.ArcGIS.Controls.AxLicenseControl(); ((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axTOCControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axPageLayoutControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).BeginInit(); this.SuspendLayout(); // // Label1 // this.Label1.BackColor = System.Drawing.SystemColors.Control; this.Label1.Cursor = System.Windows.Forms.Cursors.Default; this.Label1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.Label1.ForeColor = System.Drawing.SystemColors.ControlText; this.Label1.Location = new System.Drawing.Point(568, 48); this.Label1.Name = "Label1"; this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No; this.Label1.Size = new System.Drawing.Size(160, 33); this.Label1.TabIndex = 6; this.Label1.Text = "1) Load a map document into the PageLayoutControl. "; // // Label2 // this.Label2.BackColor = System.Drawing.SystemColors.Control; this.Label2.Cursor = System.Windows.Forms.Cursors.Default; this.Label2.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.Label2.ForeColor = System.Drawing.SystemColors.ControlText; this.Label2.Location = new System.Drawing.Point(568, 80); this.Label2.Name = "Label2"; this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No; this.Label2.Size = new System.Drawing.Size(152, 33); this.Label2.TabIndex = 5; this.Label2.Text = "2) Right click on a feature layer to change its symbology"; // // axToolbarControl1 // this.axToolbarControl1.Location = new System.Drawing.Point(8, 8); this.axToolbarControl1.Name = "axToolbarControl1"; this.axToolbarControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axToolbarControl1.OcxState"))); this.axToolbarControl1.Size = new System.Drawing.Size(712, 28); this.axToolbarControl1.TabIndex = 7; // // axTOCControl1 // this.axTOCControl1.Location = new System.Drawing.Point(8, 40); this.axTOCControl1.Name = "axTOCControl1"; this.axTOCControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axTOCControl1.OcxState"))); this.axTOCControl1.Size = new System.Drawing.Size(192, 352); this.axTOCControl1.TabIndex = 8; this.axTOCControl1.OnMouseDown += new ESRI.ArcGIS.Controls.ITOCControlEvents_Ax_OnMouseDownEventHandler(this.axTOCControl1_OnMouseDown); // // axPageLayoutControl1 // this.axPageLayoutControl1.Location = new System.Drawing.Point(208, 40); this.axPageLayoutControl1.Name = "axPageLayoutControl1"; this.axPageLayoutControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axPageLayoutControl1.OcxState"))); this.axPageLayoutControl1.Size = new System.Drawing.Size(352, 352); this.axPageLayoutControl1.TabIndex = 9; // // axLicenseControl1 // this.axLicenseControl1.Enabled = true; this.axLicenseControl1.Location = new System.Drawing.Point(576, 136); this.axLicenseControl1.Name = "axLicenseControl1"; this.axLicenseControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axLicenseControl1.OcxState"))); this.axLicenseControl1.Size = new System.Drawing.Size(32, 32); this.axLicenseControl1.TabIndex = 10; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(728, 398); this.Controls.Add(this.axLicenseControl1); this.Controls.Add(this.axPageLayoutControl1); this.Controls.Add(this.axTOCControl1); this.Controls.Add(this.axToolbarControl1); this.Controls.Add(this.Label1); this.Controls.Add(this.Label2); this.Name = "Form1"; this.Text = "Layer Rendering"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axTOCControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axPageLayoutControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).EndInit(); this.ResumeLayout(false); } #endregion [STAThread] static void Main() { if (!RuntimeManager.Bind(ProductCode.Engine)) { if (!RuntimeManager.Bind(ProductCode.Desktop)) { MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down."); return; } } Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { //Set buddy control axToolbarControl1.SetBuddyControl(axPageLayoutControl1); axTOCControl1.SetBuddyControl(axPageLayoutControl1); //Add ToolbarControl items axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsPageZoomInTool", -1, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsPageZoomOutTool", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsPageZoomWholePageCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsPageFocusNextMapCommand", -1, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsPageFocusPreviousMapCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsSelectTool", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); } private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e) { //Exit if not right mouse button if (e.button != 2) return; IBasicMap map = new MapClass(); ILayer layer = new FeatureLayerClass(); object other = new Object(); object index = new Object(); esriTOCControlItem item = new esriTOCControlItem(); //Determine what kind of item has been clicked on axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); //QI to IFeatureLayer and IGeoFeatuerLayer interface if (layer == null) return; IFeatureLayer featureLayer = layer as IFeatureLayer; if (featureLayer == null) return; IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer) featureLayer; ISimpleRenderer simpleRenderer = (ISimpleRenderer) geoFeatureLayer.Renderer; //Create the form with the SymbologyControl frmSymbol symbolForm = new frmSymbol(); //Get the IStyleGalleryItem IStyleGalleryItem styleGalleryItem = null; //Select SymbologyStyleClass based upon feature type switch (featureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassMarkerSymbols, simpleRenderer.Symbol); break; case esriGeometryType.esriGeometryPolyline: styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassLineSymbols, simpleRenderer.Symbol); break; case esriGeometryType.esriGeometryPolygon: styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassFillSymbols, simpleRenderer.Symbol); break; } //Release the form symbolForm.Dispose(); this.Activate(); if (styleGalleryItem == null) return; //Create a new renderer simpleRenderer = new SimpleRendererClass(); //Set its symbol from the styleGalleryItem simpleRenderer.Symbol = (ISymbol) styleGalleryItem.Item; //Set the renderer into the geoFeatureLayer geoFeatureLayer.Renderer = (IFeatureRenderer) simpleRenderer; //Fire contents changed event that the TOCControl listens to axPageLayoutControl1.ActiveView.ContentsChanged(); //Refresh the display axPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null); } } }
[Visual Basic .NET]
LayerRendering.vb
Option Strict Off Option Explicit On Imports ESRI.ArcGIS.Carto Imports ESRI.ArcGIS.Controls Imports ESRI.ArcGIS.Display Imports ESRI.ArcGIS.Geometry Imports ESRI.ArcGIS.SystemUI Imports ESRI.ArcGIS Friend Class Form1 Inherits System.Windows.Forms.Form #Region "Windows Form Designer generated code " Public Sub New() MyBase.New() 'Load runtime If Not RuntimeManager.Bind(ProductCode.Engine) Then If Not RuntimeManager.Bind(ProductCode.Desktop) Then MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.") System.Environment.Exit(1) ' Force exit or other indication in the application End If End If 'This call is required by the Windows Form Designer. InitializeComponent() End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean) 'Release COM objects ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown() If Disposing Then If Not components Is Nothing Then components.Dispose() End If End If MyBase.Dispose(Disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer Public WithEvents Label1 As System.Windows.Forms.Label Public WithEvents Label2 As System.Windows.Forms.Label 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents AxToolbarControl1 As ESRI.ArcGIS.Controls.AxToolbarControl Friend WithEvents AxLicenseControl1 As ESRI.ArcGIS.Controls.AxLicenseControl Friend WithEvents AxTOCControl1 As ESRI.ArcGIS.Controls.AxTOCControl Friend WithEvents AxPageLayoutControl1 As ESRI.ArcGIS.Controls.AxPageLayoutControl <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.Label1 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.AxToolbarControl1 = New ESRI.ArcGIS.Controls.AxToolbarControl Me.AxLicenseControl1 = New ESRI.ArcGIS.Controls.AxLicenseControl Me.AxTOCControl1 = New ESRI.ArcGIS.Controls.AxTOCControl Me.AxPageLayoutControl1 = New ESRI.ArcGIS.Controls.AxPageLayoutControl CType(Me.AxToolbarControl1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.AxTOCControl1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.AxPageLayoutControl1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'Label1 ' Me.Label1.BackColor = System.Drawing.SystemColors.Control Me.Label1.Cursor = System.Windows.Forms.Cursors.Default Me.Label1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText Me.Label1.Location = New System.Drawing.Point(496, 40) Me.Label1.Name = "Label1" Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label1.Size = New System.Drawing.Size(160, 33) Me.Label1.TabIndex = 4 Me.Label1.Text = "1) Load a map document into the PageLayoutControl. " ' 'Label2 ' Me.Label2.BackColor = System.Drawing.SystemColors.Control Me.Label2.Cursor = System.Windows.Forms.Cursors.Default Me.Label2.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText Me.Label2.Location = New System.Drawing.Point(496, 72) Me.Label2.Name = "Label2" Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label2.Size = New System.Drawing.Size(152, 33) Me.Label2.TabIndex = 3 Me.Label2.Text = "2) Right click on a feature layer to change its symbology" ' 'AxToolbarControl1 ' Me.AxToolbarControl1.Location = New System.Drawing.Point(8, 8) Me.AxToolbarControl1.Name = "AxToolbarControl1" Me.AxToolbarControl1.OcxState = CType(resources.GetObject("AxToolbarControl1.OcxState"), System.Windows.Forms.AxHost.State) Me.AxToolbarControl1.Size = New System.Drawing.Size(648, 28) Me.AxToolbarControl1.TabIndex = 5 ' 'AxLicenseControl1 ' Me.AxLicenseControl1.Enabled = True Me.AxLicenseControl1.Location = New System.Drawing.Point(496, 112) Me.AxLicenseControl1.Name = "AxLicenseControl1" Me.AxLicenseControl1.OcxState = CType(resources.GetObject("AxLicenseControl1.OcxState"), System.Windows.Forms.AxHost.State) Me.AxLicenseControl1.Size = New System.Drawing.Size(32, 32) Me.AxLicenseControl1.TabIndex = 7 ' 'AxTOCControl1 ' Me.AxTOCControl1.Location = New System.Drawing.Point(8, 40) Me.AxTOCControl1.Name = "AxTOCControl1" Me.AxTOCControl1.OcxState = CType(resources.GetObject("AxTOCControl1.OcxState"), System.Windows.Forms.AxHost.State) Me.AxTOCControl1.Size = New System.Drawing.Size(152, 368) Me.AxTOCControl1.TabIndex = 8 ' 'AxPageLayoutControl1 ' Me.AxPageLayoutControl1.Location = New System.Drawing.Point(168, 40) Me.AxPageLayoutControl1.Name = "AxPageLayoutControl1" Me.AxPageLayoutControl1.OcxState = CType(resources.GetObject("AxPageLayoutControl1.OcxState"), System.Windows.Forms.AxHost.State) Me.AxPageLayoutControl1.Size = New System.Drawing.Size(320, 368) Me.AxPageLayoutControl1.TabIndex = 9 ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.BackColor = System.Drawing.SystemColors.Control Me.ClientSize = New System.Drawing.Size(664, 414) Me.Controls.Add(Me.AxPageLayoutControl1) Me.Controls.Add(Me.AxTOCControl1) Me.Controls.Add(Me.AxLicenseControl1) Me.Controls.Add(Me.AxToolbarControl1) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.Label2) Me.Cursor = System.Windows.Forms.Cursors.Default Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog Me.Location = New System.Drawing.Point(4, 23) Me.Name = "Form1" Me.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Text = "Layer Rendering" CType(Me.AxToolbarControl1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.AxTOCControl1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.AxPageLayoutControl1, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load 'Set buddy control AxToolbarControl1.SetBuddyControl(AxPageLayoutControl1) AxTOCControl1.SetBuddyControl(AxPageLayoutControl1) 'Add ToolbarControl items AxToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly) AxToolbarControl1.AddItem("esriControls.ControlsPageZoomInTool", -1, -1, True, 0, esriCommandStyles.esriCommandStyleIconOnly) AxToolbarControl1.AddItem("esriControls.ControlsPageZoomOutTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly) AxToolbarControl1.AddItem("esriControls.ControlsPageZoomWholePageCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly) AxToolbarControl1.AddItem("esriControls.ControlsPageFocusNextMapCommand", -1, -1, True, 0, esriCommandStyles.esriCommandStyleIconOnly) AxToolbarControl1.AddItem("esriControls.ControlsPageFocusPreviousMapCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly) AxToolbarControl1.AddItem("esriControls.ControlsSelectTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly) End Sub Private Sub AxTOCControl1_OnMouseDown(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent) Handles AxTOCControl1.OnMouseDown 'Exit if not right mouse button If (e.button <> 2) Then Exit Sub Dim map As IMap = New MapClass Dim layer As ILayer = New FeatureLayerClass Dim other As Object = New Object Dim index As Object = New Object Dim item As esriTOCControlItem 'Determine what kind of item has been clicked on AxTOCControl1.HitTest(e.x, e.y, item, map, layer, other, index) If layer Is Nothing Then Exit Sub If Not TypeOf layer Is IFeatureLayer Then Exit Sub 'QI to IFeatureLayer and IGeoFeatuerLayer interface Dim featureLayer As IFeatureLayer = layer Dim geoFeatureLayer As IGeoFeatureLayer = featureLayer Dim simpleRenderer As ISimpleRenderer = geoFeatureLayer.Renderer 'Create the form with the SymbologyControl Dim symbolForm As New frmSymbol 'Get the IStyleGalleryItem Dim styleGalleryItem As IStyleGalleryItem = Nothing 'Select SymbologyStyleClass based upon feature type Select Case featureLayer.FeatureClass.ShapeType Case esriGeometryType.esriGeometryPoint styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassMarkerSymbols, simpleRenderer.Symbol) Case esriGeometryType.esriGeometryPolyline styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassLineSymbols, simpleRenderer.Symbol) Case esriGeometryType.esriGeometryPolygon styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassFillSymbols, simpleRenderer.Symbol) End Select 'Release the form symbolForm.Dispose() Me.Activate() If styleGalleryItem Is Nothing Then Exit Sub 'Create a new renderer simpleRenderer = New SimpleRendererClass 'Set its symbol from the styleGalleryItem simpleRenderer.Symbol = styleGalleryItem.Item 'Set the renderer into the geoFeatureLayer geoFeatureLayer.Renderer = simpleRenderer 'Fire contents changed event that the TOCControl listens to AxPageLayoutControl1.ActiveView.ContentsChanged() 'Refresh the display AxPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewGeography, Nothing, Nothing) End Sub End Class