About the ToolbarControl MDI application Sample
[C#]
ParentForm.cs
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);
}
}
}
[Visual Basic .NET]
ParentForm.vb
Option Explicit On
Imports System
Imports System.Windows.Forms
Imports ESRI.ArcGIS.SystemUI
Imports ESRI.ArcGIS.Controls
Imports ESRI.ArcGIS
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine)
'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 MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem9 As System.Windows.Forms.MenuItem
Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar
Friend WithEvents AxToolbarControl1 As ESRI.ArcGIS.Controls.AxToolbarControl
Friend WithEvents AxLicenseControl1 As ESRI.ArcGIS.Controls.AxLicenseControl
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
Me.MainMenu1 = New System.Windows.Forms.MainMenu(Me.components)
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.MenuItem4 = New System.Windows.Forms.MenuItem
Me.MenuItem6 = New System.Windows.Forms.MenuItem
Me.MenuItem5 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem7 = New System.Windows.Forms.MenuItem
Me.MenuItem8 = New System.Windows.Forms.MenuItem
Me.MenuItem9 = New System.Windows.Forms.MenuItem
Me.ToolBar1 = New System.Windows.Forms.ToolBar
Me.AxToolbarControl1 = New ESRI.ArcGIS.Controls.AxToolbarControl
Me.AxLicenseControl1 = New ESRI.ArcGIS.Controls.AxLicenseControl
CType(Me.AxToolbarControl1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem3, Me.MenuItem4, Me.MenuItem6, Me.MenuItem5})
Me.MenuItem1.Text = "&File"
'
'MenuItem3
'
Me.MenuItem3.Index = 0
Me.MenuItem3.Text = "&New..."
'
'MenuItem4
'
Me.MenuItem4.Index = 1
Me.MenuItem4.Text = "&Close..."
'
'MenuItem6
'
Me.MenuItem6.Index = 2
Me.MenuItem6.Text = "-"
'
'MenuItem5
'
Me.MenuItem5.Index = 3
Me.MenuItem5.Text = "Exit"
'
'MenuItem2
'
Me.MenuItem2.Index = 1
Me.MenuItem2.MdiList = True
Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem7, Me.MenuItem8, Me.MenuItem9})
Me.MenuItem2.Text = "&Window"
'
'MenuItem7
'
Me.MenuItem7.Index = 0
Me.MenuItem7.Text = "Cascade"
'
'MenuItem8
'
Me.MenuItem8.Index = 1
Me.MenuItem8.Text = "Tile Horizontally"
'
'MenuItem9
'
Me.MenuItem9.Index = 2
Me.MenuItem9.Text = "Tile Vertically"
'
'ToolBar1
'
Me.ToolBar1.DropDownArrows = True
Me.ToolBar1.Location = New System.Drawing.Point(0, 0)
Me.ToolBar1.Name = "ToolBar1"
Me.ToolBar1.ShowToolTips = True
Me.ToolBar1.Size = New System.Drawing.Size(672, 42)
Me.ToolBar1.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(656, 28)
Me.AxToolbarControl1.TabIndex = 5
'
'AxLicenseControl1
'
Me.AxLicenseControl1.Enabled = True
Me.AxLicenseControl1.Location = New System.Drawing.Point(240, 48)
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 = 6
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(672, 417)
Me.ControlBox = False
Me.Controls.Add(Me.AxLicenseControl1)
Me.Controls.Add(Me.AxToolbarControl1)
Me.Controls.Add(Me.ToolBar1)
Me.IsMdiContainer = True
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "MDI Application"
CType(Me.AxToolbarControl1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
<STAThread()> _
Shared Sub Main()
'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
Application.Run(New Form1())
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Make an MDI parent
Me.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)
End Sub
Private Sub Form1_MdiChildActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MdiChildActivate
Dim activeMdiChild As ChildForm
activeMdiChild = Me.ActiveMdiChild
If (activeMdiChild Is Nothing) Then Exit Sub
'Set the ToolbarControl's buddy
AxToolbarControl1.SetBuddyControl(activeMdiChild.AxMapControl1.Object)
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
'Create a new child form
Dim newMDIChild As New ChildForm
newMDIChild.MdiParent = Me
newMDIChild.Show()
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
'Close the active child form
Dim activeMdiChild As ChildForm
activeMdiChild = Me.ActiveMdiChild
activeMdiChild.Close()
End Sub
Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.Click
Me.LayoutMdi(System.Windows.Forms.MdiLayout.Cascade)
End Sub
Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.Click
Me.LayoutMdi(System.Windows.Forms.MdiLayout.TileHorizontal)
End Sub
Private Sub MenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem9.Click
Me.LayoutMdi(System.Windows.Forms.MdiLayout.TileVertical)
End Sub
Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click
'Close any child forms and exit application
Dim i As Integer
For i = 0 To Me.MdiChildren.Length - 1
Me.MdiChildren(0).Close()
Next
Application.Exit()
End Sub
End Class