Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering


You are here: Visual Basic > Advanced VB6 tutorial > Chapter 13

Accessing Ready-Made Control Features with the UserControl's Extender Object

The ActiveX standard allows all container objects, such as Forms and PictureBox controls, to provide certain members (properties, events, and methods) to all controls (including custom ActiveX controls) that are placed on their surfaces. Some of these members might include, for instance, Top, Left, Width, and Height properties, an Enabled property, a Move method, and GotFocus and LostFocus events.

These ready-made members provided by your control's container object are all contained in an object known as the Extender that belongs to your custom control.

Your custom ActiveX control will therefore already have certain methods, properties, and events provided for it automatically through its Extender object. If you had just created an ActiveX control by putting a new UserControl object into your project and had not yet implemented any of your own custom members, you would still see quite a few default properties in the control's Properties Window when you tested it (see Figure 13.5). These properties would be the properties provided in the Extender object.

The custom control instance whose properties we are viewing in this test project doesn't have any custom properties, yet we see many properties provided through the Extender object in its Properties Window
FIGURE 13.5 The custom control instance whose properties we are viewing in this test project doesn't have any custom properties, yet we see many properties provided through the Extender object in its Properties Window

As control author, you should not be very concerned about the Extender object's members since they are intended for the developer's use.

However, you may check the values of Extender properties in order to find out what the developer or the design-time environment has done with your control.

For instance your control may have a Label whose Caption represents the Caption of your custom control. As you know it's customary for a VB control with a Caption property to begin life with its caption equal to the control's name. You can emulate this behavior by checking the Name property of the Extender object in your control's InitProperties event procedure and setting your control's Caption to the value of the Name, as in the following line of code:

lblCaption.Caption = Extender.Name

NOTE - Standard (More or Less) Extender Properties : The ActiveX standard recommends (but does not require) that all containers implement the following Extender properties: Name, Visible, Parent, Cancel, Default. You may, however, confidently reference all these properties in code without fearing an error, since VB returns default values for any of the above properties not implemented by a container.

WARNING - Naming Conflicts Between Extender and Custom Members : If you implement a member with the same name as an Extender member, the Extender member will always override your custom member because the developer will always see the Extender member and not your custom member.

WARNING - Don't Change Extender Properties in Code : You should never try to change the values of Extender properties. You will cause runtime errors or get unpredictable results. In particular, you may be tempted to use the Visible property of the Extender object to make your control invisible. Instead of this Extender property, you should use the UserControl's InvisibleAtRunTime property.


  

<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved