ArcObjects Library Reference  

TextTool

About the Creating a toolbar of globe tools Sample

[C#]

TextTool.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using System.Windows.Forms;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Analyst3D;
using ESRI.ArcGIS.GlobeCore;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using Microsoft.VisualBasic;

namespace GlobeGraphicsToolbar
{
    public class TextTool : ESRI.ArcGIS.Desktop.AddIns.Tool
    {
        private const int LeftButton = 1;
        private const esriSRGeoCSType GeographicCoordinateSystem = esriSRGeoCSType.esriSRGeoCS_WGS1984;
        private const float TextElementSize = 10;
        private const string GraphicsLayerName = "Globe Graphics";
        private object _missing = Type.Missing;

        public TextTool()
        {
        }

        protected override void OnUpdate()
        {

        }

        protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            if (arg.Button == MouseButtons.Left)
            {
                GeographicCoordinates geographicCoordinates = new GeographicCoordinates(ArcGlobe.Globe, arg.X, arg.Y);

                SpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceFactory((int)GeographicCoordinateSystem);

                PointGeometry pointGeometry = new PointGeometry(geographicCoordinates.Longitude, geographicCoordinates.Latitude, geographicCoordinates.AltitudeInKilometers, spatialReferenceFactory.SpatialReference);

                TextForm textForm = new TextForm();

                DialogResult dialogResult = textForm.ShowDialog();

                if (textForm.InputText.Length > 0)
                {
                    TextElement textElement = new TextElement(pointGeometry.Geometry, textForm.InputText, TextElementSize);

                    TableOfContents tableOfContents = new TableOfContents(ArcGlobe.Globe);

                    if (!tableOfContents.LayerExists(GraphicsLayerName))
                    {
                        tableOfContents.ConstructLayer(GraphicsLayerName);
                    }

                    Layer layer = new Layer(tableOfContents[GraphicsLayerName]);

                    layer.AddElement(textElement.Element, textElement.ElementProperties);

                    ArcGlobe.Globe.GlobeDisplay.RefreshViewers();
                }
            }
        }
    }

}

[Visual Basic .NET]

TextTool.vb

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.IO
Imports ESRI.ArcGIS.ADF.BaseClasses
Imports ESRI.ArcGIS.ADF.CATIDs
Imports System.Windows.Forms
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Analyst3D
Imports ESRI.ArcGIS.GlobeCore
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Display
Imports Microsoft.VisualBasic

Namespace GlobeGraphicsToolbar
	Public Class TextTool
		Inherits ESRI.ArcGIS.Desktop.AddIns.Tool
		Private Const LeftButton As Integer = 1
        Private Const GeographicCoordinateSystem As ESRI.ArcGIS.Geometry.esriSRGeoCSType = ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984
		Private Const TextElementSize As Single = 10
		Private Const GraphicsLayerName As String = "Globe Graphics"
		Private _missing As Object = Type.Missing

		Public Sub New()
		End Sub

		Protected Overrides Sub OnUpdate()

		End Sub

		Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs)
			If arg.Button = MouseButtons.Left Then
				Dim geographicCoordinates As New GeographicCoordinates(ArcGlobe.Globe, arg.X, arg.Y)

				Dim spatialReferenceFactory As New SpatialReferenceFactory(CInt(Fix(GeographicCoordinateSystem)))

				Dim pointGeometry As New PointGeometry(geographicCoordinates.Longitude, geographicCoordinates.Latitude, geographicCoordinates.AltitudeInKilometers, spatialReferenceFactory.SpatialReference)

				Dim textForm As New TextForm()

				Dim dialogResult As DialogResult = textForm.ShowDialog()

				If textForm.InputText.Length > 0 Then
					Dim textElement As New TextElement(pointGeometry.Geometry, textForm.InputText, TextElementSize)

					Dim tableOfContents As New TableOfContents(ArcGlobe.Globe)

					If (Not tableOfContents.LayerExists(GraphicsLayerName)) Then
						tableOfContents.ConstructLayer(GraphicsLayerName)
					End If

					Dim layer As New Layer(tableOfContents(GraphicsLayerName))

					layer.AddElement(textElement.Element, textElement.ElementProperties)

					ArcGlobe.Globe.GlobeDisplay.RefreshViewers()
				End If
			End If
		End Sub
	End Class

End Namespace