ActiveControl Property (AForm)

Returns the control that has the focus.

Syntax

[ pControl = ] Object.ActiveControl

The ActiveControl property syntax has the following parts:

 

Name

Type

Description

Object

AForm

AForm object

pControl

AControl

The last control that has the focus. When a form is referenced, ActiveControl specifies the control that would have the focus if the referenced form were active.

Comments

This property is not available at design time and is read-only at run time.

A control that has the focus can receive keyboard input. In the Microsoft Windows environment, only one window, form, or control can have this ability at a time. The object that "has the focus" is normally indicated by a highlighted caption or title bar. The focus can be set by the user or by the application using the SetFocus method.

You can use ActiveControl to access a control standard properties or methods. For example, ActiveControl.Tag = "0".

Each form can have an active control regardless of whether or not the form is active. You can write code that manipulates the active control on each form in your application even when the form isn't the active form.

This property is especially useful in a multiple-document interface (MDI) application where a button on a toolbar must initiate an action on a control in an MDI child form. When a user clicks the Copy button on the toolbar, your code can reference the text in the active control on the MDI child form, as in ActiveForm.ActiveControl.SelText.

Note: If you plan to pass the ActiveControl to a procedure, you must declare the argument in that procedure with the type AControl rather than specifying a control type (ATextBox, etc.) even if ActiveControl always refers to the same type of control.

Example

The following statement assigns the active control text to a string variable:

Procedure MyForm.GetActiveControlText(): Void

lb: AListBox

{

if Form.ActiveControl.Name="txtEdit"

return Form.ActiveControl.Object.Text

elseif Form.ActiveControl.Name="lbList"

lb=Form.ActiveControl.Object

return lb.List(lb.ListIndex)

else

return ""

endif

}

Applies to

AForm

See Also

MDIActiveForm, OnGotFocus, OnLostFocus, SetFocus