method Elements.Add ([Caption as Variant], [X as Variant], [Y as Variant])
Adds an Element object to the collection and returns a reference to the newly created object.

TypeDescription
Caption as Variant A String expression that specifies the caption to be displayed on the element. The Caption property specifies the value of the Caption parameter. Use the CaptionAlign property to align the element's caption.
X as Variant A long expression that specifies the x-position where the element is sown. If missing, the element is shown at (0,0) position on the surface. The X property indicates the element's x-position on the surface.
Y as Variant A long expression that specifies the y-position where the element is sown. If missing, the element is shown at (0,0) position on the surface. The X property indicates the element's x-position on the surface.
ReturnDescription
ElementAn Element object that represents the newly created and added element.
The Add method adds programmatically a new element to the surface. Use the Insert method to insert programmatically a child element. Use the InsertControl method to insert programmatically a child element that hosts an inner ActiveX control. The control fires the AddElement event once a new element is added to the Elements collection. The AutoSize property specifies whether the element's size if computed automatically based on its content. While the AutoSize property is True, the element is not resizable. Use the Width / Height property to specify the size of the element. The AllowCreateObject property specifies the combination of keys that allows the user to create objects on the surface.

The following samples show how you can programmatically add a new element:

VBA (MS Access, Excell...)

With Surface1
	With .Elements
		.Add "new 1"
		.Add "new 1",24,24
	End With
End With

VB6

With Surface1
	With .Elements
		.Add "new 1"
		.Add "new 1",24,24
	End With
End With

VB.NET

With Exsurface1
	With .Elements
		.Add("new 1")
		.Add("new 1",24,24)
	End With
End With

VB.NET for /COM

With AxSurface1
	With .Elements
		.Add("new 1")
		.Add("new 1",24,24)
	End With
End With

C++

/*
	Copy and paste the following directives to your header file as
	it defines the namespace 'EXSURFACELib' for the library: 'ExSurface 1.0 Control Library'

	#import <ExSurface.dll>
	using namespace EXSURFACELib;
*/
EXSURFACELib::ISurfacePtr spSurface1 = GetDlgItem(IDC_SURFACE1)->GetControlUnknown();
EXSURFACELib::IElementsPtr var_Elements = spSurface1->GetElements();
	var_Elements->Add("new 1",vtMissing,vtMissing);
	var_Elements->Add("new 1",long(24),long(24));

C++ Builder

Exsurfacelib_tlb::IElementsPtr var_Elements = Surface1->Elements;
	var_Elements->Add(TVariant("new 1"),TNoParam(),TNoParam());
	var_Elements->Add(TVariant("new 1"),TVariant(24),TVariant(24));

C#

exontrol.EXSURFACELib.Elements var_Elements = exsurface1.Elements;
	var_Elements.Add("new 1",null,null);
	var_Elements.Add("new 1",24,24);

JavaScript

<OBJECT classid="clsid:AC1DF7F4-0919-4364-8167-2F9B5155EA4B" id="Surface1"></OBJECT>

<SCRIPT LANGUAGE="JScript">
	var var_Elements = Surface1.Elements;
		var_Elements.Add("new 1",null,null);
		var_Elements.Add("new 1",24,24);
</SCRIPT>

C# for /COM

EXSURFACELib.Elements var_Elements = axSurface1.Elements;
	var_Elements.Add("new 1",null,null);
	var_Elements.Add("new 1",24,24);

X++ (Dynamics Ax 2009)

public void init()
{
	COM com_Elements;
	anytype var_Elements;
	;

	super();

	var_Elements = exsurface1.Elements(); com_Elements = var_Elements;
		com_Elements.Add("new 1");
		com_Elements.Add("new 1",COMVariant::createFromInt(24),COMVariant::createFromInt(24));
}

Delphi 8 (.NET only)

with AxSurface1 do
begin
	with Elements do
	begin
		Add('new 1',Nil,Nil);
		Add('new 1',TObject(24),TObject(24));
	end;
end

Delphi (standard)

with Surface1 do
begin
	with Elements do
	begin
		Add('new 1',Null,Null);
		Add('new 1',OleVariant(24),OleVariant(24));
	end;
end

VFP

with thisform.Surface1
	with .Elements
		.Add("new 1")
		.Add("new 1",24,24)
	endwith
endwith

dBASE Plus

local oSurface,var_Elements

oSurface = form.Activex1.nativeObject
var_Elements = oSurface.Elements
	var_Elements.Add("new 1")
	var_Elements.Add("new 1",24,24)

XBasic (Alpha Five)

Dim oSurface as P
Dim var_Elements as P

oSurface = topparent:CONTROL_ACTIVEX1.activex
var_Elements = oSurface.Elements
	var_Elements.Add("new 1")
	var_Elements.Add("new 1",24,24)

Visual Objects

local var_Elements as IElements

var_Elements := oDCOCX_Exontrol1:Elements
	var_Elements:Add("new 1",nil,nil)
	var_Elements:Add("new 1",24,24)

PowerBuilder

OleObject oSurface,var_Elements

oSurface = ole_1.Object
var_Elements = oSurface.Elements
	var_Elements.Add("new 1")
	var_Elements.Add("new 1",24,24)

Visual DataFlex

Procedure OnCreate
	Forward Send OnCreate
	Variant voElements
	Get ComElements to voElements
	Handle hoElements
	Get Create (RefClass(cComElements)) to hoElements
	Set pvComObject of hoElements to voElements
		Get ComAdd of hoElements "new 1" Nothing Nothing to Nothing
		Get ComAdd of hoElements "new 1" 24 24 to Nothing
	Send Destroy to hoElements
End_Procedure

XBase++

#include "AppEvent.ch"
#include "ActiveX.ch"

PROCEDURE Main
 	LOCAL oForm
	LOCAL nEvent := 0, mp1 := NIL, mp2 := NIL, oXbp := NIL
	LOCAL oElements
	LOCAL oSurface

	oForm := XbpDialog():new( AppDesktop() )
	oForm:drawingArea:clipChildren := .T.
	oForm:create( ,,{100,100}, {640,480},, .F. )
	oForm:close  := {|| PostAppEvent( xbeP_Quit )}

	oSurface := XbpActiveXControl():new( oForm:drawingArea )
	oSurface:CLSID  := "Exontrol.Surface.1" /*{AC1DF7F4-0919-4364-8167-2F9B5155EA4B}*/
	oSurface:create(,, {10,60},{610,370} )

		oElements := oSurface:Elements()
			oElements:Add("new 1")
			oElements:Add("new 1",24,24)

	oForm:Show()
	DO WHILE nEvent != xbeP_Quit
		nEvent := AppEvent( @mp1, @mp2, @oXbp )
		oXbp:handleEvent( nEvent, mp1, mp2 )
	ENDDO 
RETURN