I am trying to convert an ArcObjects tool written in VB to an ArcGIS Pro SDK tool written in C#. One of the subroutines of my ArcObjects passes a layout graphics container and a text element name on the layout to make the text color black and another subroutine is passed the same kinds of parameters to change the text color to null (invisible). Here is the ArcObjects method for making the color of the text black:
Private Sub setTextElementBlackColor(ByVal pGraphicsContainer As ESRI.ArcGIS.Carto.IGraphicsContainer, ByVal strElementName As String)
Dim pActiveView As ESRI.ArcGIS.Carto.IActiveView
Dim bFound As Boolean
Dim pElement As ESRI.ArcGIS.Carto.IElement
Dim pElementProperties As ESRI.ArcGIS.Carto.IElementProperties2
Dim pTextElement As ESRI.ArcGIS.Carto.ITextElement
Dim pTextSymbol As ESRI.ArcGIS.Display.ITextSymbol
Dim pColor As ESRI.ArcGIS.Display.IColor
pActiveView = pGraphicsContainer
pColor = New ESRI.ArcGIS.Display.RgbColorClass
pColor.NullColor = False
pColor.RGB = RGB(0, 0, 0)
pTextSymbol = New ESRI.ArcGIS.Display.TextSymbolClass
'Element Search escape variable
bFound = False
pGraphicsContainer.Reset()
pElement = pGraphicsContainer.Next()
Do While Not pElement Is Nothing
pElementProperties = pElement
If pElementProperties.Name = strElementName Then
If TypeOf pElement Is ESRI.ArcGIS.Carto.ITextElement Then
pTextElement = pElement
pTextSymbol = pTextElement.Symbol
pTextSymbol.Color = pColor
pTextElement.Symbol = pTextSymbol
pActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics, Nothing, Nothing)
bFound = True
If Not pTextSymbol Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(pTextSymbol)
End If
If Not pTextElement Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(pTextElement)
End If
End If
End If
If bFound = False Then
pElement = pGraphicsContainer.Next()
Else
pElement = Nothing
End If
If Not pElementProperties Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(pElementProperties)
End If
Loop
If Not pColor Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(pColor)
End If
If Not pActiveView Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(pActiveView)
End If
End Sub
What is the equivalent code in the ArcGIS Pro SDK for changing a layout text element to black or invisible?
I have a method for changing the text of a TextElement, but the TextProperties of the element do not include any way to change the text color. Presumably the code would be similar to that code for changing the text element color, but I do not see any sample code in the git hub examples that tells me how to access the color properties of the text element. Here is the code I use to change the text value of the TextElement:
public async static void SetTextElement(string ElementName, string TextValue)
{
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
//Reference and load the layout associated with the layout item
Layout lyt = LayoutView.Active.Layout;
if (lyt != null)
{
//Reference a text element by name
TextElement txtElm = lyt.FindElement(ElementName) as TextElement;
//Change TextProperties
TextProperties txt_prop = txtElm.TextProperties;
txt_prop.Text = TextValue;
txtElm.SetTextProperties(txt_prop);
}
});
}