<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to programmatically add an active graphics layer to a map? in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-programmatically-add-an-active-graphics/m-p/677033#M18122</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm writing a WPF applicating, in C#, using ArcObjects.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have an ESRI.ArcGIS.Controls.AxMapControl on my form, and I'm trying to draw some graphics elements on top of it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The map I'm developing with is a customer-provided mdf of the state of Georgia.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying an example I found here: &lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001rv000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001rv000000&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void AddTextElement(IMap map, double x, double y)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IGraphicsContainer graphicsContainer = map as IGraphicsContainer;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IElement element = new TextElementClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ITextElement textElement = element as ITextElement;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Create a point as the shape of the element.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IPoint point = new PointClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; point.X = x;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; point.Y = y;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; element.Geometry = point;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; textElement.Text = "Hello World";
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphicsContainer.AddElement(element, 0);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Flag the new text to invalidate.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IActiveView activeView = map as IActiveView;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It took while to figure out how to project the lat/long of Atlanta to the coordinate system of the map, but I'm pretty sure that I've got it right. The x/y values I'm passing into AddTextElement() are clearly within the Atlanta area, according to the Location data I see when I use the Identify tool on the map.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I'm not seeing the text. Everything seems to be working correctly, but I'm not seeing the text.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can see a number of possibilities:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- The layer I'm adding the TextElement to isn't visible, or doesn't exist.&lt;/P&gt;&lt;P&gt;- I need to apply a spatial reference system to the point I'm setting as the TextElement's geometry&lt;/P&gt;&lt;P&gt;- The text is drawing fine, but there's something wrong with the font - it's invisibly small, or in a transparent color, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haven't a clue, which.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was hoping there was something obvious I was missing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--- More info ---&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've been looking at a different tutorial:&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.esri.com/help/9.3/arcgisengine/dotnet/7bd52ed1-18ae-4aa7-8cde-e9eaed9537fe.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.esri.com/help/9.3/arcgisengine/dotnet/7bd52ed1-18ae-4aa7-8cde-e9eaed9537fe.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This includes a custom control that writes the current date to the map, at the point that you click it with the mouse:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void OnMouseDown(int Button, int Shift, int X, int Y)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Get the active view.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IActiveView activeView = m_hookHelper.ActiveView;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Create a new text element.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ITextElement textElement = new TextElementClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Create a text symbol.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ITextSymbol textSymbol = new TextSymbolClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; textSymbol.Size = 25;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Set the text element properties.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; textElement.Symbol = textSymbol;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; textElement.Text = DateTime.Now.ToShortDateString();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Query interface (QI) for IElement.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IElement element = (IElement)textElement;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Create a point.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IPoint point = new PointClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Set the element's geometry.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; element.Geometry = point;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Add the element to the graphics container.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; activeView.GraphicsContainer.AddElement(element, 0);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Refresh the graphics.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This actually succeeds in writing text to the map, but it confuses me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I click on the map, and enter into OnMouseDown, X is 183 and Y is 266 - clearly pixel coordinates. (That they are of type int would suggest that.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The but after point is created, by calling DisplayTransformation.ToMapPoint(), it has X and Y of 2.5048801369863014 and 8.3338184931506856. That's not lat/long and it's not map coordinates. But when I use that as my TextElement's geometry and add it to the GraphicsContainer, it does display the text on the map.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are these some sort of screen coordinates?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If so, how do I convert lat/long to screen coordinates?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And if they are screen coordinates, why doesn't my first example work, when I use the screen coordinate values to locate the text?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;P&gt;So, I added the custom control from the second example to the map on the first. Noticed two things:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. The coordinates of the point returned by activeView.ScreenDisplay.DisplayTransformation.ToMapPoint() appear to be map coordinates.&lt;/P&gt;&lt;P&gt;2. I still don't see the text appear on the map.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This suggests to me that the problem isn't coordinates, or fonts, or colors, but that there isn't an active graphics layer on the map.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I add one?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 1em; color: #242729; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;At this point, I have to say "never mind".&lt;/P&gt;&lt;P style="margin-bottom: 1em; color: #242729; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;Turns out my problem is scaling. My text is being drawn on the map, only at a scale that is invisible unless I zoom in considerably. My "Hello, world" text is drawn at a fixed size, on the map, and scales with the map. With a default size of only a hundred feet or so, which isn't visible when zoomed to see the entire state. If I set the size to 25, it's a bit larger, but still essentially invisible. I need to set it to 25000 before its legible on the map.&lt;/P&gt;&lt;P style="margin-bottom: 1em; color: #242729; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;What I need, now, is to figure out how to draw markers and text on the map at a size that is independent of the zoom level. And that's another question, entirely.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 04:31:49 GMT</pubDate>
    <dc:creator>JeffreyDege</dc:creator>
    <dc:date>2021-12-12T04:31:49Z</dc:date>
    <item>
      <title>How to programmatically add an active graphics layer to a map?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-programmatically-add-an-active-graphics/m-p/677033#M18122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm writing a WPF applicating, in C#, using ArcObjects.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have an ESRI.ArcGIS.Controls.AxMapControl on my form, and I'm trying to draw some graphics elements on top of it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The map I'm developing with is a customer-provided mdf of the state of Georgia.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying an example I found here: &lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001rv000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001rv000000&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void AddTextElement(IMap map, double x, double y)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IGraphicsContainer graphicsContainer = map as IGraphicsContainer;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IElement element = new TextElementClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ITextElement textElement = element as ITextElement;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Create a point as the shape of the element.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IPoint point = new PointClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; point.X = x;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; point.Y = y;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; element.Geometry = point;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; textElement.Text = "Hello World";
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphicsContainer.AddElement(element, 0);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Flag the new text to invalidate.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IActiveView activeView = map as IActiveView;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It took while to figure out how to project the lat/long of Atlanta to the coordinate system of the map, but I'm pretty sure that I've got it right. The x/y values I'm passing into AddTextElement() are clearly within the Atlanta area, according to the Location data I see when I use the Identify tool on the map.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I'm not seeing the text. Everything seems to be working correctly, but I'm not seeing the text.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can see a number of possibilities:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- The layer I'm adding the TextElement to isn't visible, or doesn't exist.&lt;/P&gt;&lt;P&gt;- I need to apply a spatial reference system to the point I'm setting as the TextElement's geometry&lt;/P&gt;&lt;P&gt;- The text is drawing fine, but there's something wrong with the font - it's invisibly small, or in a transparent color, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haven't a clue, which.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was hoping there was something obvious I was missing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--- More info ---&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've been looking at a different tutorial:&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.esri.com/help/9.3/arcgisengine/dotnet/7bd52ed1-18ae-4aa7-8cde-e9eaed9537fe.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.esri.com/help/9.3/arcgisengine/dotnet/7bd52ed1-18ae-4aa7-8cde-e9eaed9537fe.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This includes a custom control that writes the current date to the map, at the point that you click it with the mouse:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void OnMouseDown(int Button, int Shift, int X, int Y)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Get the active view.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IActiveView activeView = m_hookHelper.ActiveView;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Create a new text element.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ITextElement textElement = new TextElementClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Create a text symbol.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ITextSymbol textSymbol = new TextSymbolClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; textSymbol.Size = 25;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Set the text element properties.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; textElement.Symbol = textSymbol;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; textElement.Text = DateTime.Now.ToShortDateString();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Query interface (QI) for IElement.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IElement element = (IElement)textElement;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Create a point.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IPoint point = new PointClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Set the element's geometry.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; element.Geometry = point;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Add the element to the graphics container.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; activeView.GraphicsContainer.AddElement(element, 0);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Refresh the graphics.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This actually succeeds in writing text to the map, but it confuses me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I click on the map, and enter into OnMouseDown, X is 183 and Y is 266 - clearly pixel coordinates. (That they are of type int would suggest that.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The but after point is created, by calling DisplayTransformation.ToMapPoint(), it has X and Y of 2.5048801369863014 and 8.3338184931506856. That's not lat/long and it's not map coordinates. But when I use that as my TextElement's geometry and add it to the GraphicsContainer, it does display the text on the map.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are these some sort of screen coordinates?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If so, how do I convert lat/long to screen coordinates?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And if they are screen coordinates, why doesn't my first example work, when I use the screen coordinate values to locate the text?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;P&gt;So, I added the custom control from the second example to the map on the first. Noticed two things:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. The coordinates of the point returned by activeView.ScreenDisplay.DisplayTransformation.ToMapPoint() appear to be map coordinates.&lt;/P&gt;&lt;P&gt;2. I still don't see the text appear on the map.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This suggests to me that the problem isn't coordinates, or fonts, or colors, but that there isn't an active graphics layer on the map.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I add one?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 1em; color: #242729; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;At this point, I have to say "never mind".&lt;/P&gt;&lt;P style="margin-bottom: 1em; color: #242729; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;Turns out my problem is scaling. My text is being drawn on the map, only at a scale that is invisible unless I zoom in considerably. My "Hello, world" text is drawn at a fixed size, on the map, and scales with the map. With a default size of only a hundred feet or so, which isn't visible when zoomed to see the entire state. If I set the size to 25, it's a bit larger, but still essentially invisible. I need to set it to 25000 before its legible on the map.&lt;/P&gt;&lt;P style="margin-bottom: 1em; color: #242729; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;What I need, now, is to figure out how to draw markers and text on the map at a size that is independent of the zoom level. And that's another question, entirely.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:31:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-programmatically-add-an-active-graphics/m-p/677033#M18122</guid>
      <dc:creator>JeffreyDege</dc:creator>
      <dc:date>2021-12-12T04:31:49Z</dc:date>
    </item>
  </channel>
</rss>

