ArcObjects Library Reference (Controls)  

IPageLayoutControl3.AddElement Method

Adds the supplied element to the PageLayout, with optional geometry, symbolization, name and Z order.

[Visual Basic .NET]
Public Sub AddElement ( _
    ByVal pElement As IElement, _
    [ByVal Geometry As Object], _
    [ByVal Symbology As Object], _
    [ByVal Name As Object], _
    [ByVal ZOrder As Integer] _
)
[C#]
public void AddElement (
    IElement pElement,
    object Geometry,
    object Symbology,
    object Name,
    int ZOrder
);
[C#]

Optional Values

Geometry   To indicate that this parameter is undefined, pass in Type.Missing.
Symbology   To indicate that this parameter is undefined, pass in Type.Missing.
Name   To indicate that this parameter is undefined, pass in Type.Missing.
ZOrder   Supply 0 as a default value.
[C++]
HRESULT AddElement(
  IElement* pElement,
  VARIANT Geometry,
  VARIANT Symbology,
  VARIANT Name,
  long ZOrder
);
[C++]

Parameters

pElement [in]

  pElement is a parameter of type IElement

Geometry [optional]   Geometry is a parameter of type VARIANT

  To indicate this parameter is undefined pass in a VARIANT with type VT_ERROR and scode value of DISP_E_PARAMNOTFOUND.

Symbology [optional]   Symbology is a parameter of type VARIANT

  To indicate this parameter is undefined pass in a VARIANT with type VT_ERROR and scode value of DISP_E_PARAMNOTFOUND.

Name [optional]   Name is a parameter of type VARIANT

  To indicate this parameter is undefined pass in a VARIANT with type VT_ERROR and scode value of DISP_E_PARAMNOTFOUND.

ZOrder [in, optional, defaultvalue(0)]   ZOrder is a parameter of type long

Product Availability

Available with ArcGIS Engine.

Description

Adds an element to the GraphicsContainer.

geometry an object that implements IGeometry
symbology an object that implements ISymbol or IColor (symbology is applied to the element using the IPropertySupport interface)
name a string

Errors Returned

1006 800A03EE: The element parameter does not support the IElement interface 

1007 800A03EF: Symbology can not be applied to element as the element does not implement IElementPropertySupport 

1009 800A03F1: The geometry parameter does not contain an object that supports IGeometry 

1010 800A03F2: The symbology parameter does not contain a valid object 

1011 800A03F3: The name parameter does not contain a valid string

[C#]

The following code example adds a new element that implements IEnvelope and is colored Red.

private void axPageLayoutControl1_OnMouseDown(object sender, ESRI.ArcGIS.PageLayoutControl.IPageLayoutControlEvents_OnMouseDownEvent e)
{
    IRgbColor rgbColor = new RgbColorClass();
    rgbColor.Red = 255;
    axPageLayoutControl1.AddElement(new RectangleElement(), axPageLayoutControl1.TrackRectangle(), rgbColor,null,-1);       axPageLayoutControl1.CtlRefresh(esriViewDrawPhase.esriViewGraphics,null,null);
}
[Visual Basic .NET]

The following code example adds a new element that implements IEnvelope and is colored Red.

Private Sub AxPageLayoutControl1_OnMouseDown(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.PageLayoutControl.IPageLayoutControlEvents_OnMouseDownEvent) Handles AxPageLayoutControl1.OnMouseDown
  Dim pRgbColor As IRgbColor
  pRgbColor = New RgbColorClass
  pRgbColor.Red = 
  255 AxPageLayoutControl1.AddElement(New RectangleElement, AxPageLayoutControl1.TrackRectangle,
  pRgbColor)
End Sub

See Also

IPageLayoutControl3 Interface