About the Enable layer drag and drop in the TOCControl Sample
[C#]
LayerDragDrop.cs
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.SystemUI; using ESRI.ArcGIS; namespace LayerDragDrop { public class Form1 : System.Windows.Forms.Form { internal System.Windows.Forms.CheckBox chkDragDrop; internal System.Windows.Forms.Label Label6; internal System.Windows.Forms.Label Label5; internal System.Windows.Forms.Label Label2; internal System.Windows.Forms.Label Label4; internal System.Windows.Forms.Label Label3; internal System.Windows.Forms.Label Label1; 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() { // // Required for Windows Form Designer support // InitializeComponent(); } protected override void Dispose( bool disposing ) { 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.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.chkDragDrop = new System.Windows.Forms.CheckBox(); this.Label6 = new System.Windows.Forms.Label(); this.Label5 = new System.Windows.Forms.Label(); this.Label2 = new System.Windows.Forms.Label(); this.Label4 = new System.Windows.Forms.Label(); this.Label3 = new System.Windows.Forms.Label(); this.Label1 = 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(); // // chkDragDrop // this.chkDragDrop.Location = new System.Drawing.Point(432, 16); this.chkDragDrop.Name = "chkDragDrop"; this.chkDragDrop.Size = new System.Drawing.Size(168, 16); this.chkDragDrop.TabIndex = 5; this.chkDragDrop.Text = "Layer Drag and Drop"; this.chkDragDrop.Click += new System.EventHandler(this.chkDragDrop_Click); // // Label6 // this.Label6.Location = new System.Drawing.Point(432, 234); this.Label6.Name = "Label6"; this.Label6.Size = new System.Drawing.Size(184, 56); this.Label6.TabIndex = 16; this.Label6.Text = "6) Move a layer into the new map by dragging and dropping a layer whilst holding " + "the CTRL key down inside the TOCControl"; // // Label5 // this.Label5.Location = new System.Drawing.Point(432, 184); this.Label5.Name = "Label5"; this.Label5.Size = new System.Drawing.Size(184, 56); this.Label5.TabIndex = 15; this.Label5.Text = "5) Copy a layer into the new map by dragging and dropping a layer inside the TOCC" + "ontrol"; // // Label2 // this.Label2.Location = new System.Drawing.Point(432, 96); this.Label2.Name = "Label2"; this.Label2.Size = new System.Drawing.Size(176, 32); this.Label2.TabIndex = 12; this.Label2.Text = "3) Re-order the layers in the TOCControl"; // // Label4 // this.Label4.Location = new System.Drawing.Point(432, 128); this.Label4.Name = "Label4"; this.Label4.Size = new System.Drawing.Size(176, 56); this.Label4.TabIndex = 14; this.Label4.Text = "4) Right click on the PageLayoutControl and drag a rectangle to create a new MapF" + "rame"; // // Label3 // this.Label3.Location = new System.Drawing.Point(432, 72); this.Label3.Name = "Label3"; this.Label3.Size = new System.Drawing.Size(176, 32); this.Label3.TabIndex = 13; this.Label3.Text = "2) Enable layer drag and drop"; // // Label1 // this.Label1.Location = new System.Drawing.Point(432, 40); this.Label1.Name = "Label1"; this.Label1.Size = new System.Drawing.Size(176, 32); this.Label1.TabIndex = 11; this.Label1.Text = "1) Load a map document into the PageLayoutControl"; // // 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(416, 28); this.axToolbarControl1.TabIndex = 17; // // 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(144, 344); this.axTOCControl1.TabIndex = 18; // // axPageLayoutControl1 // this.axPageLayoutControl1.Location = new System.Drawing.Point(160, 40); this.axPageLayoutControl1.Name = "axPageLayoutControl1"; this.axPageLayoutControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axPageLayoutControl1.OcxState"))); this.axPageLayoutControl1.Size = new System.Drawing.Size(256, 344); this.axPageLayoutControl1.TabIndex = 19; this.axPageLayoutControl1.OnMouseDown += new ESRI.ArcGIS.Controls.IPageLayoutControlEvents_Ax_OnMouseDownEventHandler(this.axPageLayoutControl1_OnMouseDown); // // axLicenseControl1 // this.axLicenseControl1.Enabled = true; this.axLicenseControl1.Location = new System.Drawing.Point(56, 48); 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 = 20; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(616, 390); this.Controls.Add(this.axLicenseControl1); this.Controls.Add(this.axPageLayoutControl1); this.Controls.Add(this.axTOCControl1); this.Controls.Add(this.axToolbarControl1); this.Controls.Add(this.Label6); this.Controls.Add(this.Label5); this.Controls.Add(this.Label2); this.Controls.Add(this.Label4); this.Controls.Add(this.Label3); this.Controls.Add(this.Label1); this.Controls.Add(this.chkDragDrop); this.Name = "Form1"; this.Text = "Layer Drag and Drop"; 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 items to the ToolbarControl 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.ControlsPageFocusPreviousMapCommand",-1,-1,true,0,esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsPageFocusNextMapCommand",-1,-1,false,0,esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand",-1,-1,true,0,esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool",-1,-1,false,0,esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool",-1,-1,false,0,esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsSelectTool",-1,-1,true,0,esriCommandStyles.esriCommandStyleIconOnly); } private void chkDragDrop_Click(object sender, System.EventArgs e) { //Enable layer and drag and drop axTOCControl1.EnableLayerDragDrop = chkDragDrop.Checked; } private void axPageLayoutControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent e) { if (e. button == 1) return; //Create an envelope by tracking a rectangle IEnvelope envelope = axPageLayoutControl1.TrackRectangle(); //Create a map frame element with a new map IMapFrame mapFrame = new MapFrameClass(); mapFrame.Map = new MapClass(); //Add the map frame to the PageLayoutControl with specified geometry axPageLayoutControl1.AddElement((IElement)mapFrame, envelope, null, null, 0); //Refresh the PageLayoutControl axPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); } } }
[Visual Basic .NET]
LayerDragDrop.vb
Imports ESRI.ArcGIS.Geometry Imports ESRI.ArcGIS.Carto Imports ESRI.ArcGIS.SystemUI Imports ESRI.ArcGIS Public 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() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) 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 '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 AxTOCControl1 As ESRI.ArcGIS.Controls.AxTOCControl Friend WithEvents AxToolbarControl1 As ESRI.ArcGIS.Controls.AxToolbarControl Friend WithEvents AxPageLayoutControl1 As ESRI.ArcGIS.Controls.AxPageLayoutControl Friend WithEvents AxLicenseControl1 As ESRI.ArcGIS.Controls.AxLicenseControl Friend WithEvents chkDragDrop As System.Windows.Forms.CheckBox Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents Label6 As System.Windows.Forms.Label <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1)) Me.AxTOCControl1 = New ESRI.ArcGIS.Controls.AxTOCControl Me.AxToolbarControl1 = New ESRI.ArcGIS.Controls.AxToolbarControl Me.AxPageLayoutControl1 = New ESRI.ArcGIS.Controls.AxPageLayoutControl Me.AxLicenseControl1 = New ESRI.ArcGIS.Controls.AxLicenseControl Me.chkDragDrop = New System.Windows.Forms.CheckBox Me.Label1 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.Label3 = New System.Windows.Forms.Label Me.Label4 = New System.Windows.Forms.Label Me.Label5 = New System.Windows.Forms.Label Me.Label6 = New System.Windows.Forms.Label CType(Me.AxTOCControl1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.AxToolbarControl1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.AxPageLayoutControl1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' '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(144, 328) Me.AxTOCControl1.TabIndex = 0 ' '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(424, 28) Me.AxToolbarControl1.TabIndex = 1 ' 'AxPageLayoutControl1 ' Me.AxPageLayoutControl1.Location = New System.Drawing.Point(160, 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(272, 328) Me.AxPageLayoutControl1.TabIndex = 2 ' 'AxLicenseControl1 ' Me.AxLicenseControl1.Enabled = True Me.AxLicenseControl1.Location = New System.Drawing.Point(56, 56) 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 = 3 ' 'chkDragDrop ' Me.chkDragDrop.Location = New System.Drawing.Point(440, 16) Me.chkDragDrop.Name = "chkDragDrop" Me.chkDragDrop.Size = New System.Drawing.Size(168, 16) Me.chkDragDrop.TabIndex = 4 Me.chkDragDrop.Text = "Layer Drag and Drop" ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(440, 48) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(176, 32) Me.Label1.TabIndex = 5 Me.Label1.Text = "1) Load a map document into the PageLayoutControl" ' 'Label2 ' Me.Label2.Location = New System.Drawing.Point(440, 104) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(176, 32) Me.Label2.TabIndex = 6 Me.Label2.Text = "3) Re-order the layers in the TOCControl" ' 'Label3 ' Me.Label3.Location = New System.Drawing.Point(440, 80) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(176, 32) Me.Label3.TabIndex = 7 Me.Label3.Text = "2) Enable layer drag and drop" ' 'Label4 ' Me.Label4.Location = New System.Drawing.Point(440, 136) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(176, 56) Me.Label4.TabIndex = 8 Me.Label4.Text = "4) Right click on the PageLayoutControl and drag a rectangle to create a new MapF" & _ "rame" ' 'Label5 ' Me.Label5.Location = New System.Drawing.Point(440, 192) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(184, 56) Me.Label5.TabIndex = 9 Me.Label5.Text = "5) Copy a layer into the new map by dragging and dropping a layer inside the TOCC" & _ "ontrol" ' 'Label6 ' Me.Label6.Location = New System.Drawing.Point(440, 239) Me.Label6.Name = "Label6" Me.Label6.Size = New System.Drawing.Size(184, 56) Me.Label6.TabIndex = 10 Me.Label6.Text = "6) Move a layer into the new map by dragging and dropping a layer whilst holding " & _ "the CTRL key down inside the TOCControl" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(624, 374) Me.Controls.Add(Me.Label6) Me.Controls.Add(Me.Label5) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.chkDragDrop) Me.Controls.Add(Me.AxLicenseControl1) Me.Controls.Add(Me.AxPageLayoutControl1) Me.Controls.Add(Me.AxToolbarControl1) Me.Controls.Add(Me.AxTOCControl1) Me.Name = "Form1" Me.Text = "Layer Drag and Drop" CType(Me.AxTOCControl1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.AxToolbarControl1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.AxPageLayoutControl1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Set buddy control AxToolbarControl1.SetBuddyControl(AxPageLayoutControl1) AxTOCControl1.SetBuddyControl(AxPageLayoutControl1) 'Add items to the ToolbarControl 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.ControlsPageFocusPreviousMapCommand", -1, -1, True, 0, esriCommandStyles.esriCommandStyleIconOnly) AxToolbarControl1.AddItem("esriControls.ControlsPageFocusNextMapCommand", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly) AxToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", -1, -1, True, 0, esriCommandStyles.esriCommandStyleIconOnly) AxToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly) AxToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", -1, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly) AxToolbarControl1.AddItem("esriControls.ControlsSelectTool", -1, -1, True, 0, esriCommandStyles.esriCommandStyleIconOnly) End Sub Private Sub chkDragDrop_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkDragDrop.Click 'Enable layer and drag and drop AxTOCControl1.EnableLayerDragDrop = chkDragDrop.Checked End Sub Private Sub AxPageLayoutControl1_OnMouseDown(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent) Handles AxPageLayoutControl1.OnMouseDown If e.button = 1 Then Exit Sub 'Create an envelope by tracking a rectangle Dim envelope As IEnvelope envelope = AxPageLayoutControl1.TrackRectangle() 'Create a map frame element with a new map Dim mapFrame As IMapFrame mapFrame = New MapFrameClass mapFrame.Map = New MapClass 'Add the map frame to the PageLayoutControl with specified geometry AxPageLayoutControl1.AddElement(mapFrame, envelope, Nothing, Nothing, 0) 'Refresh the PageLayoutControl AxPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewGraphics, Nothing, Nothing) End Sub End Class