On Designing ActiveX Controls VB Help

In this section I’m going to discuss briefly the similarities and differences among ActiveX controls ActiveX components and standard projects. Before I get to the details of how to build Activex controls, I want to show you how they relate to other types of projects.This information will help you get the big picture and put together the pieces of the following sections.

A standard application consists of a main Form and several (optional) auxiliary Forms. The auxiliary Forms usually support the main Form as they usually accept  user data !hat are processed by the code in the main Form. You can think of an ActiveX control as a Form and think of its Properties window and Property Pages as the auxiliary Forms.

An application interacts with the user through its interface. The designer of the application decides how the Forms interact with the user and the user has to following these rules. Something similar happens with ActiveX controls. The ActiveX control provides a well-defined-interface which consists of properties and methods. This is
the only “y to manipulate the control. Just as users of your applications don’t have access to the source code and can’t modify the application developers can’t see the control’s source code and must access an ActiveX control through the interface exposed by the control.

In the last chapter you learned how to implement interfaces consisting of properties and methods and how to raise events from within an ActiveX component. This  is how you build the interface of an ActiveX control.You implement properties as Property procedures, and you implement methods as Public procedures. Whereas an ActiveX component may provide a few properties and methods, an ActiveX. .control must provide a large number of properties. When a developer places your custom control on a Form, he or she expects to see the properties that are common all the controls that are visible at run time (properties to the control’s  as its color the text font, the Index and Tag’ properties, and so on). The developer also expects to be able to program all the common events such as the mouse  <U\cl keyboard events as well as some events that are unique to the custom control.

The ‘design of an ActiveX control is similar to the design of a Form. You place controls on a Form-like object called User Control which is the control’s Form. It provides nearly all the methods of a standard Form such as the Print method the Line method and so on. In other words, you can use familiar programming techniques to draw an ActiveX control or you can use existing controls to build a custom ActiveX control.

The Forms of an application are the windows..you see on the Desktop when the application is executed. When you design the application you. can rearrange the controls on a Form and program how they react to user action At the time these Forms will appear on the Desktop. ActiveX controls are also windows, only  hey ” can’t exist on their own and they can’t be placed on the Desktop. They must be placed on Forms.

The major difference between applications and custom controls is that custom controls can exist in two run time modes. When the developer places a control on a Form, the control is actually running. When you set a control’s property through the Properties window something happens to the control; its appearance changes,
or the control rejects the.changes. This means that the code of the custom control is executing, even though the project on which the control is used in design mode. When the developer starts the application, the custom control is already running.However the control must be able to distinguish when the project is in design or
execution mode and behave accordingly

Consider a simple Text Box control at design time. Its Text property is Text.if you set its Multi Line property to True and the Scroll bar property to Vertical vertical scroll bar will be attached to the control automatically Obviously some statements are executed while the project is in design mode. Then you start the application, enter some text in the Text Box control and end it. When the project is back in design mode the control’s Text property is reset to Text. The control has stored-its settings before the project switched from design time to run time mode and restored them when the project returned to design mode again.

This dual run time mode of an ActiveX control is something new to VB programmers and you’ll have to get used to it. When you design custom ActiveX ‘ controls; you must also switch between the roles of the ActiveX developer (the programmer who designs the control) and the role of the application developer (the programmer who uses the control).

In summary a custom ActiveX control is an application with a visible user interface as well as an invisible programming interface. The-visible interface is what the developer sees when placing an instance of the control on the Form, which is also what the user sees on the Form when the project is placed in run time  ode. The developer can manipulate the control through the properties exposed by the control I ‘ (at design time) and through its methods (at run time). The properties and methods  “constitute the control’s invisible interface (or the developer interface as opposed to the user interface). You, the ActiveX control developer will develop the visible user interface on a User Control object which is almost identical to-the Form object. It’s like designing a standard application. As far as the control’s invisible interface goes it’s .’like designing a Class Module.

Posted on November 5, 2015 in Building AdiveX Controls

Share the Story

Back to Top