Dim pMxDoc As IMxDocument Dim pPageLayout As IPageLayout Dim pGraphics As IGraphicsContainerSelect Set pMxDoc = ThisDocument Set pPageLayout = pMxDoc.PageLayout Set pGraphics = pPageLayout If pGraphics.ElementSelectionCount <> 1 Then MsgBox "Select only 1 map element.", vbOKOnly Exit Sub End If If TypeOf pGraphics.DominantElement Is ITextElement Then Dim te As ITextElement Set te = pGraphics.DominantElement Dim e As IElement Set e = te Dim p As IPolygon Set p = New Polygon e.QueryOutline pMxDoc.activeView.ScreenDisplay, p MsgBox "Width: " & p.Envelope.Width & " Height: " & p.Envelope.Height End If
Hi Ann,I am working on converting some VBA to C# Add-Ins. Next on my plate is one that builds some ParagraphText boxes. I'll post a snip of C# here in the next few days.If you post a few more details on what you want to accomplish, that would help.-Jeff
using System.Drawing; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.ADF.COMSupport; // Also add references to "stdole" and "ESRI.ArcGIS.ADF.Local" to the project. //... // Call the method in your add-in button click such as: // string txt = @This is just a bunch of text to place...; // BuildParaText(txt); private void BuildParaText(string paraText) { IActiveView activeView = ArcMap.Document.ActiveView; if (activeView is IPageLayout) { ITextElement paraTextElement = new ParagraphTextElementClass(); // notice casts here IFrameProperties frameProperties = paraTextElement as IFrameProperties; IMarginProperties marginProperties = paraTextElement as IMarginProperties; IColumnProperties columnProperties = paraTextElement as IColumnProperties; ITextElement textElement = paraTextElement as ITextElement; IElement element = paraTextElement as IElement; // Set the margin and column count marginProperties.Margin = 4; columnProperties.Count = 1; // Reusable color object IRgbColor rgbColor = new RgbColorClass(); // Outline, black ISimpleLineSymbol outline = new SimpleLineSymbolClass(); rgbColor.Red = 0; rgbColor.Green = 0; rgbColor.Blue = 0; rgbColor.Transparency = 255; outline.Color = rgbColor; outline.Width = 0.5; outline.Style = esriSimpleLineStyle.esriSLSSolid; // Fill, white ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); rgbColor.Red = 255; rgbColor.Green = 255; rgbColor.Blue = 255; rgbColor.Transparency = 255; fillSymbol.Color = rgbColor; // Set outline to fill fillSymbol.Outline = outline; // Set fill to background ISymbolBackground background = new SymbolBackgroundClass(); background.FillSymbol = fillSymbol; // Set background to frame frameProperties.Background = background; // Text symbol ISimpleTextSymbol textSymbol = new TextSymbolClass(); rgbColor.Red = 0; rgbColor.Green = 0; rgbColor.Blue = 0; Font font = new Font("Arial Narrow", 14, FontStyle.Bold); textSymbol.Font = OLE.GetIFontDispFromFont(font) as stdole.IFontDisp; textSymbol.Color = rgbColor; textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; textSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; // Set text symbol to element textElement.Symbol = textSymbol; // Set the actual text to display textElement.Text = paraText; // Set the size of the text box to 5 x 2 in display units (ie. inches) IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(0, 0, 5, 2); element.Geometry = envelope; // Add the text box to the layout IGraphicsContainer graphicsContainer = ArcMap.Document.PageLayout as IGraphicsContainer; graphicsContainer.AddElement(element, 0); activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } }
Here is code that will drop a ParagraphTextElement on the layout in the lower left corner. This was banged together quickly, but does work and shows how to get at the various options available for ParagraphTextElement. using System.Drawing; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.ADF.COMSupport; // Also add references to "stdole" and "ESRI.ArcGIS.ADF.Local" to the project. //... // Call the method in your add-in button click such as: // string txt = @This is just a bunch of text to place...; // BuildParaText(txt); private void BuildParaText(string paraText) { IActiveView activeView = ArcMap.Document.ActiveView; if (activeView is IPageLayout) { ITextElement paraTextElement = new ParagraphTextElementClass(); // notice casts here IFrameProperties frameProperties = paraTextElement as IFrameProperties; IMarginProperties marginProperties = paraTextElement as IMarginProperties; IColumnProperties columnProperties = paraTextElement as IColumnProperties; ITextElement textElement = paraTextElement as ITextElement; IElement element = paraTextElement as IElement; // Set the margin and column count marginProperties.Margin = 4; columnProperties.Count = 1; // Reusable color object IRgbColor rgbColor = new RgbColorClass(); // Outline, black ISimpleLineSymbol outline = new SimpleLineSymbolClass(); rgbColor.Red = 0; rgbColor.Green = 0; rgbColor.Blue = 0; rgbColor.Transparency = 255; outline.Color = rgbColor; outline.Width = 0.5; outline.Style = esriSimpleLineStyle.esriSLSSolid; // Fill, white ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); rgbColor.Red = 255; rgbColor.Green = 255; rgbColor.Blue = 255; rgbColor.Transparency = 255; fillSymbol.Color = rgbColor; // Set outline to fill fillSymbol.Outline = outline; // Set fill to background ISymbolBackground background = new SymbolBackgroundClass(); background.FillSymbol = fillSymbol; // Set background to frame frameProperties.Background = background; // Text symbol ISimpleTextSymbol textSymbol = new TextSymbolClass(); rgbColor.Red = 0; rgbColor.Green = 0; rgbColor.Blue = 0; Font font = new Font("Arial Narrow", 14, FontStyle.Bold); textSymbol.Font = OLE.GetIFontDispFromFont(font) as stdole.IFontDisp; textSymbol.Color = rgbColor; textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; textSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; // Set text symbol to element textElement.Symbol = textSymbol; // Set the actual text to display textElement.Text = paraText; // Set the size of the text box to 5 x 2 in display units (ie. inches) IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(0, 0, 5, 2); element.Geometry = envelope; // Add the text box to the layout IGraphicsContainer graphicsContainer = ArcMap.Document.PageLayout as IGraphicsContainer; graphicsContainer.AddElement(element, 0); activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } }
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.