Add Method - Controls

Add a new control to the Controls collection.

App.ActiveForm.Controls.Add(Name, Type, Text, x, y, cx, cy, Parent)

Client support

   Newlook Smartclient

   Newlook Server

Parameters

Name - (String, Required)

A string that is used to specify the name of the new control. It can then be used in the same manner as any other named control created in designer to reference the control and its properties/methods.

Type - (Integer, Required)

Specifies the type of control to create. This type specified must be one of the nlCtrlxxx constants (i.e. nlCtrlLabel) or its integer value equivalent.

Refer to Control Types topic for a list of constants that can be used in this argument.

Text - (String, Optional)

The initial text for the control. If not specified, it defaults to an empty string.

x - (Integer, Optional)

Specifies the initial left coordinate (Left property) of the control's position. If not specified, it defaults to 0.

y - (Integer, Optional)

Specifies the initial top coordinate (Top property) of the control's position. If not specified, it defaults to 0.

cx - (Integer, Optional)

Specifies the initial control width (Width property). If not specified, it defaults to 0.

cy - (Integer, Optional)

Specifies the initial control height (Height property). If not specified, it defaults to 0.

Parent - (Object, Optional)

Specifies the name of the parent control which this control should be created as a child of. Child controls are clipped to their parent control. Child control's coordinates are zero-based relative to the top-left corner of the parent control. If no parent control is specified, the parent is the active form. Note, not all controls can be used as parent controls (currently only Panel and TabPage controls can be specified in this argument).

Use

This method allows you to insert a new control on the active form at runtime. This method is typically attached to the OnReceive property of the form.

Note that controls of the type nlCtrlActiveX and nlCtrlImageList cannot be inserted dynamically at run-time.

TIP

Adding an item to a collection using this method causes the count property of the collection to increment by 1.

EXAMPLES

The following script creates a 100x20 label on the form (and hence a new control in the Controls collection) with the name "lbWarning" and the display text "Alert".

J SCRIPT

function AddWarning()

{

//Create a warning label and set its properties.

App.ActiveForm.Controls.Add("lbWarning", nlCtrlLabel, "Warning", 10, 10, 100, 20);

App.ActiveForm.lbWarning.BackColor = nlClrRed;

App.ActiveForm.lbWarning.ForeColor = nlClrWhite;

App.ActiveForm.lbWarning.Blink = 1;

}

 

VB SCRIPT

Sub CreateWarningLabel

'Create a warning label and set its properties.

App.ActiveForm.Controls.Add "lbWarning", nlCtrlLabel, "Warning", 10, 10, 100, 20

App.ActiveForm.Controls.lbWarning.BackColor = RGB(255,0,0)

App.ActiveForm.Controls.lbWarning.ForeColor = nlClrWhite

App.ActiveForm.Controls.lbWarning.Blink = True

End Sub

See Also

RefreshForm Method | Remove Method | Aid Key Constants | AddNew method | AddItem method | AddRecord method | Node object | ListItem object | ColumnHeader object | Add Method - Function Keys | Add Method - Nodes | Add Method - ColumnHeaders | Add Method - Items

Applies To

Controls collection


© 2004-2021 looksoftware. All rights reserved.