English

How To: Rotate text programmatically

Summary

Instructions provided describe how to rotate text programmatically. When setting the Angle property on an ITextSymbol object, the text does not move because the Angle property is not implemented. This is a known issue at ArcGIS 8.1 and 8.2.

Procedure

The workaround is to use the interface ITransform2D.
 

  1. Start ArcMap.
  2. Create a new UIButtonControl: How To: Create a new UIButtonControl​
    Note:
     For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
  3. Right-click the UIButtonControl and select View Source.
  4. Copy this code into the UIButtonControl's click event.
     
    Code:
    Dim pMxDoc As IMxDocument 
    Set pMxDoc = ThisDocument 
    Dim pLayout As IPageLayout 
    Set pLayout = pMxDoc.PageLayout 
    
    Dim pGC As IGraphicsContainer 
    Set pGC = pLayout 
    
    Dim pFont As IFontDisp 
    Set pFont = New StdFont 
    pFont.Size = 15 
    pFont.Name = "Arial Black" 
    pFont.Bold = True 
    Dim pTextElem As ITextElement 
    Set pTextElem = New TextElement 
    
    Dim pTextSym As ITextSymbol 
    Set pTextSym = New TextSymbol 
    
    '"""""""""""""""""""""""""""""""""""""""""""" 
    '''This line is ignored at ArcGIS 8.1 and 8.2 
    pTextSym.Angle = 45 
    '"""""""""""""""""""""""""""""""""""""""" 
    pTextSym.Font = pFont 
    pTextSym.Size = pFont.Size 
    
    pTextElem.Symbol = pTextSym 
    pTextElem.Text = "TestText" 
    
    Dim pPoint As IPoint 
    Set pPoint = New Point 
    pPoint.X = 4 
    pPoint.Y = 5.5 
    
    Dim pElem As IElement 
    Set pElem = pTextElem 
    pElem.Geometry = pPoint 
    
    pGC.AddElement pElem, 0 
    '''''This is the workaround using angle... 
    Dim pTwoD As ITransform2D 
    Set pTwoD = pElem 
    pTwoD.Rotate pPoint, 0 
    
    pMxDoc.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
    
  5. Click Layout View from the View Menu.
  6. Click the new button to run the code. A new text element is added near the center of the layout. The element is rotated from the horizontal.