ArcObjects Library Reference  

TextElement

About the Creating a toolbar of globe tools Sample

[C#]

TextElement.cs

using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Analyst3D;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.GlobeCore;
using ESRI.ArcGIS.ADF.COMSupport;
using System.Drawing;
using System;


namespace GlobeGraphicsToolbar
{
    public class TextElement
    {
        private IElement _element;
        private IGlobeGraphicsElementProperties _elementProperties;

        public TextElement(IGeometry geometry, string text, float size)
        {
            _element = GetElement(geometry, text, size);
            _elementProperties = GetElementProperties();
        }

        private IElement GetElement(IGeometry geometry, string text, float size)
        {
            IElement element;

            ITextElement textElement = new TextElementClass();
            element = textElement as IElement;

            ITextSymbol textSymbol = new TextSymbolClass();
            textSymbol.Color = ColorSelection.GetColor();
            textSymbol.Size = Convert.ToDouble(size);
            textSymbol.Font = GetIFontDisp(size);
            textSymbol.HorizontalAlignment = GetHorizontalAlignment();
            textSymbol.VerticalAlignment = GetVerticalAlignment();

            element.Geometry = geometry;

            textElement.Symbol = textSymbol;
            textElement.Text = text;

            return element;
        }

        private stdole.IFontDisp GetIFontDisp(float size)
        {
            const string FontFamilyName = "Arial";
            const FontStyle FontStyle = FontStyle.Bold;

            Font font = new Font(FontFamilyName, size, FontStyle);

            return OLE.GetIFontDispFromFont(font) as stdole.IFontDisp;
        }

        private esriTextHorizontalAlignment GetHorizontalAlignment()
        {
            const esriTextHorizontalAlignment HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;

            return HorizontalAlignment;
        }

        private esriTextVerticalAlignment GetVerticalAlignment()
        {
            const esriTextVerticalAlignment VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline;

            return VerticalAlignment;
        }

        private IGlobeGraphicsElementProperties GetElementProperties()
        {
            IGlobeGraphicsElementProperties elementProperties = new GlobeGraphicsElementPropertiesClass();
            elementProperties.FixedScreenSize = true;
            elementProperties.DrapeElement = true;

            return elementProperties;
        }

        public IElement Element
        {
            get
            {
                return _element;
            }
        }

        public IGlobeGraphicsElementProperties ElementProperties
        {
            get
            {
                return _elementProperties;
            }
        }
    }
}
[Visual Basic .NET]

TextElement.vb

Imports Microsoft.VisualBasic
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Analyst3D
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.GlobeCore
Imports ESRI.ArcGIS.ADF.COMSupport
Imports System.Drawing
Imports System


Namespace GlobeGraphicsToolbar
	Public Class TextElement
		Private _element As IElement
		Private _elementProperties As IGlobeGraphicsElementProperties

		Public Sub New(ByVal geometry As IGeometry, ByVal text As String, ByVal size As Single)
			_element = GetElement(geometry, text, size)
			_elementProperties = GetElementProperties()
		End Sub

		Private Function GetElement(ByVal geometry As IGeometry, ByVal text As String, ByVal size As Single) As IElement
			Dim element As IElement

			Dim textElement As ITextElement = New TextElementClass()
			element = TryCast(textElement, IElement)

			Dim textSymbol As ITextSymbol = New TextSymbolClass()
			textSymbol.Color = ColorSelection.GetColor()
			textSymbol.Size = Convert.ToDouble(size)
			textSymbol.Font = GetIFontDisp(size)
			textSymbol.HorizontalAlignment = GetHorizontalAlignment()
			textSymbol.VerticalAlignment = GetVerticalAlignment()

			element.Geometry = geometry

			textElement.Symbol = textSymbol
			textElement.Text = text

			Return element
		End Function

		Private Function GetIFontDisp(ByVal size As Single) As stdole.IFontDisp
			Const FontFamilyName As String = "Arial"
			Const FontStyle As FontStyle = FontStyle.Bold

			Dim font As New Font(FontFamilyName, size, FontStyle)

			Return TryCast(OLE.GetIFontDispFromFont(font), stdole.IFontDisp)
		End Function

        Private Function GetHorizontalAlignment() As ESRI.ArcGIS.Display.esriTextHorizontalAlignment
            Const HorizontalAlignment As ESRI.ArcGIS.Display.esriTextHorizontalAlignment = ESRI.ArcGIS.Display.esriTextHorizontalAlignment.esriTHACenter

            Return HorizontalAlignment
        End Function

        Private Function GetVerticalAlignment() As ESRI.ArcGIS.Display.esriTextVerticalAlignment
            Const VerticalAlignment As ESRI.ArcGIS.Display.esriTextVerticalAlignment = ESRI.ArcGIS.Display.esriTextVerticalAlignment.esriTVABaseline

            Return VerticalAlignment
        End Function

		Private Function GetElementProperties() As IGlobeGraphicsElementProperties
			Dim elementProperties As IGlobeGraphicsElementProperties = New GlobeGraphicsElementPropertiesClass()
			elementProperties.FixedScreenSize = True
			elementProperties.DrapeElement = True

			Return elementProperties
		End Function

		Public ReadOnly Property Element() As IElement
			Get
				Return _element
			End Get
		End Property

		Public ReadOnly Property ElementProperties() As IGlobeGraphicsElementProperties
			Get
				Return _elementProperties
			End Get
		End Property
	End Class
End Namespace