InsertControl Method (AForm) |
Version 5 |
Insert a control with given specifications: name, type, location... into a form. This method allows you to create a control during run-time.
[ ctrl = ] Object.InsertControl ( sControlName, sControlClassType, [fLeft], [fTop], [fWidth], [fHeight], [sContainer], [bVisible], [vNameOrIndex] )
The Insert Control method syntax has the following parts:
Name |
Type |
Description |
Object |
AForm |
AForm object |
sControlName |
Val BString |
Control name |
sControlClassName |
Val BString |
Control class name |
fLeft |
Val Variant |
The X coordinate of the control. Default value = 0. |
fTop |
Val Variant |
The Y coordinate of the control. Default value = 0. |
fWidth |
Val Float |
The width for the control being inserted. Default value=100. |
fHeight |
Val Float |
The height of the control being inserted. Default value=100. |
sContainer |
Val BString |
Container name |
bVisible |
Val Bool |
Visible flag - Default value=True. |
vNameOrIndex |
Val Varient |
Control's name or index to insert at |
ctrl |
AControl |
Control created and inserted |
If no control name or index to insert at is specified, then a control will be inserted at the end.
The container name is the name of the container control. If it is a tab page (ATabPage), it must also specify the tab (ATab) name, for example "tabLog.pageAll", a tab page (ATabPage) named "pageAll" is the container and its tab name is "tabLog".
Control class can be ActiveX control or .Net (.Net only from v2022/12.0).
The following statement inserts a button control into a APanel control, pnl on the location (left, top)=(0, 10) and width being 10 and height being (panel heigtht - 10) on a form:
btn=frm.InsertControl(GetKeyFromCmd(iCmd), "AButton", 0, 10, 10, pnl.Height-10, pnl.Name)
btn.Font.Size=frm.Font.Size
btn.Caption=GetCommandMember(iCmd, ateCmdFormCaption)
btn.Visible=GetCommandStatus(iCmd, ateCmdStatusVisible, ateCmdShowForm)
btn.Enabled=GetCommandStatus(iCmd, ateCmdStatusEnable)
btn.Tag=iCmd
btn.Picture=m_frmMain.imglMiscLarge.Images(GetCommandMember(iCmd, ateCmdId)).ExtracIcon()
AddHandler btn, "OnClick", OnControlButtonClick
The following example shows the procedure AddHandler attached. The procedure must have the first parameter Val of the control:
Procedure OnControlButtonClick(ctl): Void
--------------------------------------------------------------------------------
ctl: Val AControl
iCmd: enumCommandId
{
! retrieve command index
iCmd=ctl.Tag
! execute command's procedure
....
}