LoseFocus

Description

Occurs just before a control receives focus (before it becomes selected and active).

Event ID

Event ID

Description

pbm_controltypekillfocus

UserObject (standard visual user objects only)

pbm_bnkillfocus

CheckBox, CommandButton, Graph, OLE, Picture, PictureHyperLink, PictureButton, RadioButton, StaticText, StaticHyperLink

pbm_cbnkillfocus

DropDownListBox, DropDownPictureListBox

pbm_dwnkillfocus

DataWindow

pbm_enkillfocus

SingleLineEdit, EditMask, MultiLineEdit

pbm_lbnkillfocus

ListBox, PictureListBox

pbm_lvnkillfocus

ListView

pbm_prnkillfocus

HProgressBar, VProgressBar

pbm_renkillfocus

RichTextEdit

pbm_sbnkillfocus

HScrollBar, HTrackBar, VScrollBar, VTrackBar

pbm_tcnkillfocus

Tab

pbm_tvnkillfocus

TreeView

Arguments

None

Returns

Long. Return code choices (specify in a RETURN statement):

Usage

Write a script for a control’s LoseFocus event if you want some processing to occur when the user changes focus to another control.

For controls that contain editable text, losing focus can also cause a Modified event to occur.

Because the MessageBox function grabs focus, you should not use it when focus is changing, such as in a LoseFocus event. Instead, you might display a message in the window’s title or a MultiLineEdit.

Examples

Example 1

Example 1 In this script for the LoseFocus event of a SingleLineEdit sle_town, the user is reminded to enter information if the text box is left empty:

IF sle_town.Text = "" THEN

   st_status.Text = "You have not specified a town."

END IF

Example 2

Example 2 Statements in the LoseFocus event for a DataWindow control dw_emp can trigger a user event whose script validates the last item the user entered.

This statement triggers the user event ue_accept:

dw_emp.EVENT ue_accept( )

Example 3

This statement in ue_accept calls the AcceptText function:

dw_emp.AcceptText( )

Example 4

This script for the LoseFocus event of a RichTextEdit control performs processing when the control actually loses focus:

GraphicObject l_control


// Check whether the RichTextEdit still has focus

l_control = GetFocus()

IF TypeOf(l_control) = RichTextEdit! THEN RETURN 0


// Perform processing only if RichTextEdit lost focus

...

Example 5

This script gets the name of the control instead:

GraphicObject l_control

string ls_name

l_control = GetFocus()

ls_name = l_control.Classname( )

See also