public void PerformTest() { double fromX = 0; double fromY = 0; ITextElement leftFromTextElement = new TextElementClass(); IElement leftFromElement = leftFromTextElement as IElement; IElementProperties leftFromProperties = leftFromElement as IElementProperties; leftFromProperties.Name = "LF:" + "TEST"; leftFromTextElement.Text = "Sample text to go in a callout to test gettting the size. " + "\r\nThis adds some text on a second line." + "\r\nThis adds some text on a third line."; ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(fromX, fromY + 0); leftFromElement.Geometry = point; // Create text symbology IFormattedTextSymbol textSymLeftAlign = new TextSymbol() as IFormattedTextSymbol; stdole.IFontDisp fontFrom = textSymLeftAlign.Font; fontFrom.Size = 8; textSymLeftAlign.Font = fontFrom; textSymLeftAlign.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; ICallout callOut = new BalloonCalloutClass(); textSymLeftAlign.Background = (ITextBackground)callOut; // Set anchor point ESRI.ArcGIS.Geometry.Point anchorPTFrom = new ESRI.ArcGIS.Geometry.Point(); anchorPTFrom.PutCoords(fromX, fromY); callOut.AnchorPoint = anchorPTFrom; leftFromTextElement.Symbol = textSymLeftAlign; IGraphicsContainer graphicsContainer = ArcMap.Document.ActivatedView as IGraphicsContainer; graphicsContainer.AddElement(leftFromElement, 0); leftFromElement.Activate(ArcMap.Document.ActivatedView.ScreenDisplay); //Testing to see if I can figure out extent of callout graphic IEnvelope elementEnvelope = new EnvelopeClass(); leftFromElement.QueryBounds(ArcMap.Document.ActiveView.ScreenDisplay, elementEnvelope); System.Diagnostics.Debug.WriteLine("Element: " + elementEnvelope.Width + ", " + elementEnvelope.Height); }
I put your code into a test Add-In and made as few modifications as needed to get it to run (just some constant values and document references):public void PerformTest() { double fromX = 0; double fromY = 0; ITextElement leftFromTextElement = new TextElementClass(); IElement leftFromElement = leftFromTextElement as IElement; IElementProperties leftFromProperties = leftFromElement as IElementProperties; leftFromProperties.Name = "LF:" + "TEST"; leftFromTextElement.Text = "Sample text to go in a callout to test gettting the size. " + "\r\nThis adds some text on a second line." + "\r\nThis adds some text on a third line."; ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.Point(); point.PutCoords(fromX, fromY + 0); leftFromElement.Geometry = point; // Create text symbology IFormattedTextSymbol textSymLeftAlign = new TextSymbol() as IFormattedTextSymbol; stdole.IFontDisp fontFrom = textSymLeftAlign.Font; fontFrom.Size = 8; textSymLeftAlign.Font = fontFrom; textSymLeftAlign.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; ICallout callOut = new BalloonCalloutClass(); textSymLeftAlign.Background = (ITextBackground)callOut; // Set anchor point ESRI.ArcGIS.Geometry.Point anchorPTFrom = new ESRI.ArcGIS.Geometry.Point(); anchorPTFrom.PutCoords(fromX, fromY); callOut.AnchorPoint = anchorPTFrom; leftFromTextElement.Symbol = textSymLeftAlign; IGraphicsContainer graphicsContainer = ArcMap.Document.ActivatedView as IGraphicsContainer; graphicsContainer.AddElement(leftFromElement, 0); leftFromElement.Activate(ArcMap.Document.ActivatedView.ScreenDisplay); //Testing to see if I can figure out extent of callout graphic IEnvelope elementEnvelope = new EnvelopeClass(); leftFromElement.QueryBounds(ArcMap.Document.ActiveView.ScreenDisplay, elementEnvelope); System.Diagnostics.Debug.WriteLine("Element: " + elementEnvelope.Width + ", " + elementEnvelope.Height); }
The output in Page Layout is:
Element: 2.85220000000118, 0.530399999999645
The output in Data View is:
Element: 6608.73942823708, 1228.99884448946
These look to me to correspond to the width and height of the callout box. Isn't that what you are looking for?
System.Diagnostics.Debug.WriteLine(" SpatialReference: " + (leftFromTextElement as IGraphicElement).SpatialReference.Name); System.Diagnostics.Debug.WriteLine(" UpperLeft:" + elementEnvelope.UpperLeft.X + ", " + elementEnvelope.UpperLeft.Y); System.Diagnostics.Debug.WriteLine(" LowerLeft:" + elementEnvelope.LowerLeft.X + ", " + elementEnvelope.LowerLeft.Y); System.Diagnostics.Debug.WriteLine(" UpperRight:" + elementEnvelope.UpperRight.X + ", " + elementEnvelope.UpperRight.Y); System.Diagnostics.Debug.WriteLine(" LowerRight:" + elementEnvelope.LowerRight.X + ", " + elementEnvelope.LowerRight.Y);
Running same test code as before. The corner location coordinates are correct in Layout View:
Element Size: 2.85220000000118, 0.530399999999645
UpperLeft:-0.0694000000003143, 0.436700000000201
LowerLeft:-0.0694000000003143, -0.0936999999994441
UpperRight:2.78280000000086, 0.436700000000201
LowerRight:2.78280000000086, -0.0936999999994441
I added this to get the spatial ref and corners:System.Diagnostics.Debug.WriteLine(" SpatialReference: " + (leftFromTextElement as IGraphicElement).SpatialReference.Name); System.Diagnostics.Debug.WriteLine(" UpperLeft:" + elementEnvelope.UpperLeft.X + ", " + elementEnvelope.UpperLeft.Y); System.Diagnostics.Debug.WriteLine(" LowerLeft:" + elementEnvelope.LowerLeft.X + ", " + elementEnvelope.LowerLeft.Y); System.Diagnostics.Debug.WriteLine(" UpperRight:" + elementEnvelope.UpperRight.X + ", " + elementEnvelope.UpperRight.Y); System.Diagnostics.Debug.WriteLine(" LowerRight:" + elementEnvelope.LowerRight.X + ", " + elementEnvelope.LowerRight.Y);
In Data View :
Element Size: 6608.73942823708, 1228.99884448946
SpatialReference: NAD_1983_StatePlane_California_VI_FIPS_0406_Feet
UpperLeft:-160.905063271523, 1011.83200590312
LowerLeft:-160.905063271523, -217.16683858633
UpperRight:6447.83436496556, 1011.83200590312
LowerRight:6447.83436496556, -217.16683858633
Using the Go To XY (set to Feet like the SR), and it located the corners correctly.
Ok yes I agree the code you have works and is returning the 4 corners. However, try changing your offset value for Y on the leftFromElement.Geometry to something other then 0. This way the actual callout appears away from the anchor point and will show the tail of the callout. Then see if the returned coordinates match the corners of the box.
Yeah, it looks like it returns the envelope surrounding the anchor and the balloon -- which makes sense since the element includes both.
Have you tried ITextBackground.QueryBoundary? Since the background is the ballooncallout, it seems like that should work. I don't have time to test it at the moment...