ArcObjects Library Reference  

Appearance

About the Change the appearance of the ToolbarControl Sample

[C#]

Appearance.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS;

namespace Appearance
{

	public class Form1 : System.Windows.Forms.Form
	{
		internal System.Windows.Forms.CheckBox chkFillDirection;
		internal System.Windows.Forms.Button btnFadeColor;
		internal System.Windows.Forms.Button btnBackColor;
		internal System.Windows.Forms.CheckBox chkHiddenItems;
		internal System.Windows.Forms.CheckBox chkOrientation;
		private ESRI.ArcGIS.Controls.AxToolbarControl axToolbarControl1;
		private ESRI.ArcGIS.Controls.AxGlobeControl axGlobeControl1;
		private ESRI.ArcGIS.Controls.AxLicenseControl axLicenseControl1;

		private System.ComponentModel.Container components = null;

		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
		/// <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.chkFillDirection = new System.Windows.Forms.CheckBox();
            this.btnFadeColor = new System.Windows.Forms.Button();
            this.btnBackColor = new System.Windows.Forms.Button();
            this.chkHiddenItems = new System.Windows.Forms.CheckBox();
            this.chkOrientation = new System.Windows.Forms.CheckBox();
            this.axToolbarControl1 = new ESRI.ArcGIS.Controls.AxToolbarControl();
            this.axGlobeControl1 = new ESRI.ArcGIS.Controls.AxGlobeControl();
            this.axLicenseControl1 = new ESRI.ArcGIS.Controls.AxLicenseControl();
            ((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.axGlobeControl1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).BeginInit();
            this.SuspendLayout();
            // 
            // chkFillDirection
            // 
            this.chkFillDirection.Location = new System.Drawing.Point(408, 168);
            this.chkFillDirection.Name = "chkFillDirection";
            this.chkFillDirection.Size = new System.Drawing.Size(144, 24);
            this.chkFillDirection.TabIndex = 13;
            this.chkFillDirection.Text = "Vertical Fill Direction";
            this.chkFillDirection.CheckedChanged += new System.EventHandler(this.chkFillDirection_CheckedChanged);
            // 
            // btnFadeColor
            // 
            this.btnFadeColor.Location = new System.Drawing.Point(408, 136);
            this.btnFadeColor.Name = "btnFadeColor";
            this.btnFadeColor.Size = new System.Drawing.Size(112, 23);
            this.btnFadeColor.TabIndex = 12;
            this.btnFadeColor.Text = "Fade Color";
            this.btnFadeColor.Click += new System.EventHandler(this.btnFadeColor_Click);
            // 
            // btnBackColor
            // 
            this.btnBackColor.Location = new System.Drawing.Point(408, 104);
            this.btnBackColor.Name = "btnBackColor";
            this.btnBackColor.Size = new System.Drawing.Size(112, 23);
            this.btnBackColor.TabIndex = 11;
            this.btnBackColor.Text = "Back Color";
            this.btnBackColor.Click += new System.EventHandler(this.btnBackColor_Click);
            // 
            // chkHiddenItems
            // 
            this.chkHiddenItems.Location = new System.Drawing.Point(408, 72);
            this.chkHiddenItems.Name = "chkHiddenItems";
            this.chkHiddenItems.Size = new System.Drawing.Size(152, 16);
            this.chkHiddenItems.TabIndex = 10;
            this.chkHiddenItems.Text = "Show Hidden Items";
            this.chkHiddenItems.CheckedChanged += new System.EventHandler(this.chkHiddenItems_CheckedChanged);
            // 
            // chkOrientation
            // 
            this.chkOrientation.Location = new System.Drawing.Point(408, 48);
            this.chkOrientation.Name = "chkOrientation";
            this.chkOrientation.Size = new System.Drawing.Size(152, 16);
            this.chkOrientation.TabIndex = 9;
            this.chkOrientation.Text = "Vertical Orientation";
            this.chkOrientation.CheckedChanged += new System.EventHandler(this.chkOrientation_CheckedChanged);
            // 
            // 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(490, 28);
            this.axToolbarControl1.TabIndex = 14;
            // 
            // axGlobeControl1
            // 
            this.axGlobeControl1.Location = new System.Drawing.Point(40, 40);
            this.axGlobeControl1.Name = "axGlobeControl1";
            this.axGlobeControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axGlobeControl1.OcxState")));
            this.axGlobeControl1.Size = new System.Drawing.Size(362, 391);
            this.axGlobeControl1.TabIndex = 15;
            // 
            // axLicenseControl1
            // 
            this.axLicenseControl1.Enabled = true;
            this.axLicenseControl1.Location = new System.Drawing.Point(408, 399);
            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 = 16;
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(536, 443);
            this.Controls.Add(this.axLicenseControl1);
            this.Controls.Add(this.axGlobeControl1);
            this.Controls.Add(this.axToolbarControl1);
            this.Controls.Add(this.chkFillDirection);
            this.Controls.Add(this.btnFadeColor);
            this.Controls.Add(this.btnBackColor);
            this.Controls.Add(this.chkHiddenItems);
            this.Controls.Add(this.chkOrientation);
            this.Name = "Form1";
            this.Text = "Appearance";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.axGlobeControl1)).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 chkOrientation_CheckedChanged(object sender, System.EventArgs e)
		{
		    if (chkOrientation.Checked == true) 
				axToolbarControl1.Orientation = esriToolbarOrientation.esriToolbarOrientationVertical;
			else
				axToolbarControl1.Orientation = esriToolbarOrientation.esriToolbarOrientationHorizontal;
		}

		private void chkHiddenItems_CheckedChanged(object sender, System.EventArgs e)
		{
			if (chkHiddenItems.Checked == true) 
				axToolbarControl1.ShowHiddenItems = true;
			else
				axToolbarControl1.ShowHiddenItems = false;
		}

		private void btnBackColor_Click(object sender, System.EventArgs e)
		{
			//Create new ColorDialog control
			ColorDialog colorDialog = new ColorDialog();
			//Show the ColorDialog and exit if user cancelled
			if (colorDialog.ShowDialog() == DialogResult.Cancel) return;

			//Get color from ColorDialog
			System.Drawing.Color color = colorDialog.Color;

            //The ToolbarControl host wrapper expects a SystemDrawingColor. The 
			//ToolbarControl type library wrapper expects an OLE_Color. The OLE_Color
			//is made up as follows:(Red) + (Green * 256) + (Blue * 256 * 256)		
			//IToolbarControl2 toolbarControl = (IToolbarControl2) axToolbarControl1.Object;
			//toolbarControl.BackColor = (color.R + (color.G * 256) + (color.B * 256 * 256));
			axToolbarControl1.BackColor = color;

			colorDialog = null;
		}

		private void btnFadeColor_Click(object sender, System.EventArgs e)
		{
			//Create new ColorDialog control
			ColorDialog colorDialog = new ColorDialog();
			//Show the ColorDialog and exit if user cancelled
			if (colorDialog.ShowDialog() == DialogResult.Cancel) return;

			//Get color from ColorDialog
			System.Drawing.Color color = colorDialog.Color;

			//The ToolbarControl host wrapper expects a SystemDrawingColor. The 
			//ToolbarControl type library wrapper expects an OLE_Color. The OLE_Color
			//is made up as follows:(Red) + (Green * 256) + (Blue * 256 * 256)		
			//IToolbarControl2 toolbarControl = (IToolbarControl2) axToolbarControl1.Object;
			//toolbarControl.FadeColor = (color.R + (color.G * 256) + (color.B * 256 * 256));
			axToolbarControl1.FadeColor = color;

			colorDialog = null;
		}

		private void chkFillDirection_CheckedChanged(object sender, System.EventArgs e)
		{
			if (chkFillDirection.Checked == true)
				axToolbarControl1.FillDirection = esriToolbarFillDirection.esriToolbarFillVertical;
			else
				axToolbarControl1.FillDirection = esriToolbarFillDirection.esriToolbarFillHorizontal;
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			//Set buddy control
			axToolbarControl1.SetBuddyControl(axGlobeControl1);

			//Add new items to the ToolbarControl
			axToolbarControl1.AddItem("esriControls.ControlsGlobeOpenDocCommand", 0,-1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
			axToolbarControl1.AddToolbarDef("esriControls.ControlsGlobeGlobeToolbar", -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
			axToolbarControl1.AddToolbarDef("esriControls.ControlsGlobeRotateToolbar", -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
		}
	}
}

[Visual Basic .NET]

Appearance.vb

Imports ESRI.ArcGIS.Controls
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 AxToolbarControl1 As ESRI.ArcGIS.Controls.AxToolbarControl
    Friend WithEvents AxLicenseControl1 As ESRI.ArcGIS.Controls.AxLicenseControl
    Friend WithEvents chkOrientation As System.Windows.Forms.CheckBox
    Friend WithEvents AxGlobeControl1 As ESRI.ArcGIS.Controls.AxGlobeControl
    Friend WithEvents chkHiddenItems As System.Windows.Forms.CheckBox
    Friend WithEvents btnBackColor As System.Windows.Forms.Button
    Friend WithEvents btnFadeColor As System.Windows.Forms.Button
    Friend WithEvents chkFillDirection As System.Windows.Forms.CheckBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.AxToolbarControl1 = New ESRI.ArcGIS.Controls.AxToolbarControl
        Me.AxLicenseControl1 = New ESRI.ArcGIS.Controls.AxLicenseControl
        Me.chkOrientation = New System.Windows.Forms.CheckBox
        Me.AxGlobeControl1 = New ESRI.ArcGIS.Controls.AxGlobeControl
        Me.chkHiddenItems = New System.Windows.Forms.CheckBox
        Me.btnBackColor = New System.Windows.Forms.Button
        Me.btnFadeColor = New System.Windows.Forms.Button
        Me.chkFillDirection = New System.Windows.Forms.CheckBox
        CType(Me.AxToolbarControl1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.AxGlobeControl1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        '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(450, 28)
        Me.AxToolbarControl1.TabIndex = 1
        '
        'AxLicenseControl1
        '
        Me.AxLicenseControl1.Enabled = True
        Me.AxLicenseControl1.Location = New System.Drawing.Point(365, 338)
        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 = 2
        '
        'chkOrientation
        '
        Me.chkOrientation.Location = New System.Drawing.Point(376, 40)
        Me.chkOrientation.Name = "chkOrientation"
        Me.chkOrientation.Size = New System.Drawing.Size(152, 16)
        Me.chkOrientation.TabIndex = 3
        Me.chkOrientation.Text = "Vertical Orientation"
        '
        'AxGlobeControl1
        '
        Me.AxGlobeControl1.Location = New System.Drawing.Point(40, 40)
        Me.AxGlobeControl1.Name = "AxGlobeControl1"
        Me.AxGlobeControl1.OcxState = CType(resources.GetObject("AxGlobeControl1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.AxGlobeControl1.Size = New System.Drawing.Size(319, 330)
        Me.AxGlobeControl1.TabIndex = 4
        '
        'chkHiddenItems
        '
        Me.chkHiddenItems.Location = New System.Drawing.Point(376, 64)
        Me.chkHiddenItems.Name = "chkHiddenItems"
        Me.chkHiddenItems.Size = New System.Drawing.Size(152, 16)
        Me.chkHiddenItems.TabIndex = 5
        Me.chkHiddenItems.Text = "Show Hidden Items"
        '
        'btnBackColor
        '
        Me.btnBackColor.Location = New System.Drawing.Point(376, 96)
        Me.btnBackColor.Name = "btnBackColor"
        Me.btnBackColor.Size = New System.Drawing.Size(112, 23)
        Me.btnBackColor.TabIndex = 6
        Me.btnBackColor.Text = "Back Color"
        '
        'btnFadeColor
        '
        Me.btnFadeColor.Location = New System.Drawing.Point(376, 128)
        Me.btnFadeColor.Name = "btnFadeColor"
        Me.btnFadeColor.Size = New System.Drawing.Size(112, 23)
        Me.btnFadeColor.TabIndex = 7
        Me.btnFadeColor.Text = "Fade Color"
        '
        'chkFillDirection
        '
        Me.chkFillDirection.Location = New System.Drawing.Point(376, 160)
        Me.chkFillDirection.Name = "chkFillDirection"
        Me.chkFillDirection.Size = New System.Drawing.Size(144, 24)
        Me.chkFillDirection.TabIndex = 8
        Me.chkFillDirection.Text = "Vertical Fill Direction"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(504, 382)
        Me.Controls.Add(Me.chkFillDirection)
        Me.Controls.Add(Me.btnFadeColor)
        Me.Controls.Add(Me.btnBackColor)
        Me.Controls.Add(Me.chkHiddenItems)
        Me.Controls.Add(Me.AxLicenseControl1)
        Me.Controls.Add(Me.AxGlobeControl1)
        Me.Controls.Add(Me.chkOrientation)
        Me.Controls.Add(Me.AxToolbarControl1)
        Me.Name = "Form1"
        Me.Text = "ToolbarControl Appearance"
        CType(Me.AxToolbarControl1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.AxGlobeControl1, 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(AxGlobeControl1)

        'Add new items to the ToolbarControl
        AxToolbarControl1.AddItem("esriControls.ControlsGlobeOpenDocCommand", -1, 0, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
        AxToolbarControl1.AddToolbarDef("esriControls.ControlsGlobeGlobeToolbar", -1, True, 0, esriCommandStyles.esriCommandStyleIconOnly)
        AxToolbarControl1.AddToolbarDef("esriControls.ControlsGlobeRotateToolbar", -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)

    End Sub

    Private Sub chkOrientation_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkOrientation.CheckedChanged
        If chkOrientation.Checked = True Then
            AxToolbarControl1.Orientation = esriToolbarOrientation.esriToolbarOrientationVertical
        Else
            AxToolbarControl1.Orientation = esriToolbarOrientation.esriToolbarOrientationHorizontal
        End If
    End Sub

    Private Sub chkHiddenItems_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkHiddenItems.CheckedChanged
        If chkHiddenItems.Checked = True Then
            AxToolbarControl1.ShowHiddenItems = True
        Else
            AxToolbarControl1.ShowHiddenItems = False
        End If
    End Sub

    Private Sub btnBackColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackColor.Click

        'Create new ColorDialog control
        Dim colorDialog As New ColorDialog
        'Show the ColorDialog and exit if user cancelled
        If colorDialog.ShowDialog() = Windows.Forms.DialogResult.Cancel Then Exit Sub

        'Get color from ColorDialog
        Dim color As System.Drawing.Color
        color = colorDialog.Color

        'The ToolbarControl host wrapper expects a SystemDrawingColor. The 
        'ToolbarControl type library wrapper expects an OLE_Color. The OLE_Color
        'is made up as follows:(Red) + (Green * 256) + (Blue * 256 * 256)
        'Dim toolbarControl As IToolbarControl2
        'toolbarControl = AxToolbarControl1.Object
        'toolbarControl.BackColor = (color.R + (color.G * 256) + (color.B * 256 * 256))
        AxToolbarControl1.BackColor = color

        colorDialog = Nothing

    End Sub

    Private Sub btnFadeColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFadeColor.Click

        'Create new ColorDialog control
        Dim colorDialog As New ColorDialog
        'Show the ColorDialog and exit if user cancelled
        If colorDialog.ShowDialog() = Windows.Forms.DialogResult.Cancel Then Exit Sub

        'Get color from ColorDialog
        Dim color As System.Drawing.Color
        color = colorDialog.Color

        'The ToolbarControl host wrapper expects a SystemDrawingColor. The 
        'ToolbarControl type library wrapper expects an OLE_Color. The OLE_Color
        'is made up as follows:(Red) + (Green * 256) + (Blue * 256 * 256)
        'Dim toolbarControl As IToolbarControl2
        'toolbarControl = AxToolbarControl1.Object
        'toolbarControl.FadeColor = (color.R + (color.G * 256) + (color.B * 256 * 256))
        AxToolbarControl1.FadeColor = color

        colorDialog = Nothing
    End Sub

    Private Sub chkFillDirection_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkFillDirection.CheckedChanged
        If chkFillDirection.Checked = True Then
            AxToolbarControl1.FillDirection = esriToolbarFillDirection.esriToolbarFillVertical
        Else
            AxToolbarControl1.FillDirection = esriToolbarFillDirection.esriToolbarFillHorizontal
        End If
    End Sub
End Class