ParentForm.cs
// Copyright 2010 ESRI // // All rights reserved under the copyright laws of the United States // and applicable international laws, treaties, and conventions. // // You may freely redistribute and use this sample code, with or // without modification, provided you include the original copyright // notice and use restrictions. // // See the use restrictions. // using System; using System.Windows.Forms; using ESRI.ArcGIS.SystemUI; using ESRI.ArcGIS; namespace MDIApplication { public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.MenuItem menuItem3; private System.Windows.Forms.MenuItem menuItem4; private System.Windows.Forms.MenuItem menuItem5; private System.Windows.Forms.MenuItem menuItem6; private System.Windows.Forms.MenuItem menuItem7; private System.Windows.Forms.MenuItem menuItem8; private System.Windows.Forms.ToolBar toolBar1; private System.Windows.Forms.MenuItem menuItem9; private System.ComponentModel.IContainer components; private ESRI.ArcGIS.Controls.AxToolbarControl axToolbarControl1; private ESRI.ArcGIS.Controls.AxLicenseControl axLicenseControl1; public Form1() { 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 private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); this.menuItem3 = new System.Windows.Forms.MenuItem(); this.menuItem8 = new System.Windows.Forms.MenuItem(); this.menuItem7 = new System.Windows.Forms.MenuItem(); this.menuItem4 = new System.Windows.Forms.MenuItem(); this.menuItem5 = new System.Windows.Forms.MenuItem(); this.menuItem6 = new System.Windows.Forms.MenuItem(); this.menuItem9 = new System.Windows.Forms.MenuItem(); this.toolBar1 = new System.Windows.Forms.ToolBar(); this.axToolbarControl1 = new ESRI.ArcGIS.Controls.AxToolbarControl(); this.axLicenseControl1 = new ESRI.ArcGIS.Controls.AxLicenseControl(); ((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).BeginInit(); this.SuspendLayout(); // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1, this.menuItem4}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2, this.menuItem3, this.menuItem8, this.menuItem7}); this.menuItem1.Text = "&File"; // // menuItem2 // this.menuItem2.Index = 0; this.menuItem2.Text = "&New..."; this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click); // // menuItem3 // this.menuItem3.Index = 1; this.menuItem3.Text = "&Close..."; this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click); // // menuItem8 // this.menuItem8.Index = 2; this.menuItem8.Text = "-"; // // menuItem7 // this.menuItem7.Index = 3; this.menuItem7.Text = "Exit"; this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click); // // menuItem4 // this.menuItem4.Index = 1; this.menuItem4.MdiList = true; this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem5, this.menuItem6, this.menuItem9}); this.menuItem4.Text = "&Window"; // // menuItem5 // this.menuItem5.Index = 0; this.menuItem5.Text = "Cascade"; this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click); // // menuItem6 // this.menuItem6.Index = 1; this.menuItem6.Text = "Tile Horizontally"; this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click); // // menuItem9 // this.menuItem9.Index = 2; this.menuItem9.Text = "Tile Vertically"; this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click); // // toolBar1 // this.toolBar1.DropDownArrows = true; this.toolBar1.Location = new System.Drawing.Point(0, 0); this.toolBar1.Name = "toolBar1"; this.toolBar1.ShowToolTips = true; this.toolBar1.Size = new System.Drawing.Size(752, 42); this.toolBar1.TabIndex = 3; // // 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(735, 28); this.axToolbarControl1.TabIndex = 8; // // axLicenseControl1 // this.axLicenseControl1.Enabled = true; this.axLicenseControl1.Location = new System.Drawing.Point(286, 51); 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 = 9; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(752, 452); this.ControlBox = false; this.Controls.Add(this.axLicenseControl1); this.Controls.Add(this.axToolbarControl1); this.Controls.Add(this.toolBar1); this.IsMdiContainer = true; this.Menu = this.mainMenu1; this.Name = "Form1"; this.Text = "MDI Application"; this.MdiChildActivate += new System.EventHandler(this.Form1_MdiChildActivate); this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #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) { //Make an MDI parent this.IsMdiContainer = true; //Add the commands to the ToolbarControl axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand",-1,-1,false,-1,esriCommandStyles.esriCommandStyleIconAndText); axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool",-1,-1,true,-1,esriCommandStyles.esriCommandStyleIconAndText); axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool",-1,-1,false,-1,esriCommandStyles.esriCommandStyleIconAndText); axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand",-1,-1,false,-1,esriCommandStyles.esriCommandStyleIconAndText); } private void Form1_MdiChildActivate(object sender, System.EventArgs e) { ChildForm activeMdiChild = (ChildForm) this.ActiveMdiChild; if (activeMdiChild == null) return; //Set the ToolbarControl's buddy axToolbarControl1.SetBuddyControl(activeMdiChild.ActiveControl); } private void menuItem2_Click(object sender, System.EventArgs e) { //Create a new child form ChildForm newMDIChild = new ChildForm(); newMDIChild.MdiParent = this; //Show the new child form newMDIChild.Show(); } private void menuItem3_Click(object sender, System.EventArgs e) { //Close the active child form ChildForm activeMdiChild = (ChildForm) this.ActiveMdiChild; activeMdiChild.Close(); } private void menuItem5_Click(object sender, System.EventArgs e) { this.LayoutMdi(System.Windows.Forms.MdiLayout.Cascade); } private void menuItem6_Click(object sender, System.EventArgs e) { this.LayoutMdi(System.Windows.Forms.MdiLayout.TileHorizontal); } private void menuItem7_Click(object sender, System.EventArgs e) { //Close any child forms and exit application Form[] childForm = this.MdiChildren ; for(int i=0; i < childForm.Length ; i++) childForm[i].Close(); Application.Exit(); } private void menuItem9_Click(object sender, System.EventArgs e) { this.LayoutMdi(System.Windows.Forms.MdiLayout.TileVertical); } } }