The User Controls Lost Focus Event Handler VB Help

Private Sub Textl_LostFocus()
If Len(Trim(Textl.Text)) =·0 And m_Mandatory = Required Then
TexU.BackColor = m_MandatoryColor
Textl.BackColor – leaveFocusColor
End If
End Sub


Notice that the code isn’t raising the Lost Focus event. Although the control’s behavior when it loses the focus is determined by its code you may still want to be able to program the Lost Focus event. You can use the Lost Focus event because this event can’t be triggered by the control itself. It’s triggered by the control’s container (the Form), and you can’t raise it from within the control’s code. So even though the statement Raise Event Lost Focus()doesn’t appear anywhere in the control’s code the Lost focus event can still be programmed. The same is true for the Got Focus event which is also raised by the container not by the control.

The C text box control has another feature: when it’s active it changes its background color to the value of the Enter Focus Color property:

Private Sub Textl_GotFocus()
.Textl.BackColor – EnterFocusColor
End .Sub

If you don’t like this behavior, simply set the EnterFocusColor to the same value as the control’s Background color.

To summarize ActiveX controls combine design elements from both standard VB applications and ActiveX component design. Their properties methods and events are handled just as their counterparts in ActiveX components:

• Properties are private variables, which can be read or set through Property procedures:
• Methods are public subroutines
•It Events can be raised from anywhere in an ActiveX control with the·Raise- Event method .

The control’s visible interface is drawn on a UserControl object, which is quite similar to a Fonn. It supports nearly all of a Form’s properties and methods including the Drawing methods. There are no means for loading and unloading User- Controls as there are for Forms, but you can make a control visible or invisible at run time fr~m within your code.
The code of the control resides in key events of the control such as the Paint and Re size events and is no different from the code you use to’ develop a stand alone application with similar functionality.

The integration of an ActiveX control in the development environment is the responsibility of Visual Basic. The properties you attach to the control are automatically displayed in the Properties window, and the syntax of its methods is displayed as you type code (they are incorporated into the Auto List Members feature of the Visual Basic IDE). In short, developing an ActiveX control is strikingly to developing a standard VB application. The result is a new animal that can live in various environments including Web pages, as you’ll see in the last part of this book.

Posted on November 6, 2015 in Building AdiveX Controls

Share the Story

Back to Top