![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
The code we have written takes care of displaying the current property value on the property page when the page is opened. It also disables the Text Box on the property page if more than one FancyCmdButton control is selected. We still have to write the code that moves information in the other direction: from the property page to the controls actual properties. This code is divided into two parts. First, every property page has a Changed property. You need to write code that sets this property to True if the user makes any changes to the properties listed on the page. When its Changed property is True, the property page automatically enables its Apply button, which the user clicks on to apply the new properties to the control. The ideal place to do this is in the Text Boxs Change event procedure, which will be fired whenever the user changes the contents of the Text Box. To add this code, be sure that the property page is displayed (if not, double-click on FCBGeneral in the Project box). Then double-click on the single Text Box on the page to display the code for its Change event procedure and add the code shown in Listing 17.8. Listing 17.8 The Change event procedure for the Text Box on the property page. Private Sub txtCaption_Change() Set the property pages Changed property to True if the user changes the contents of the Text Box. Changed = True End Sub Second, to apply the change, use the property pages ApplyChanges event. This event is fired when the user clicks on either the OK or the Apply button in the Property Page dialog box. Your job is to place code in this event procedure that will copy property values from the controls on the property page to the actual control properties. The details of how this is handled will depend on the specifics of your control, its properties, and so on. The code is simple for the single property in the demonstration project, consisting of the single line shown in Listing 17.9. Private Sub PropertyPage_ApplyChanges() SelectedControls(0).Caption = txtCaption.Text End Sub If we had permitted simultaneous changes to multiple selected controls, we could have used the following code. (Caution! Dont use this code in the project.) Private Sub PropertyPage_ApplyChanges() Declare a generic Object variable. Dim objControl As Variant Loop through all selected controls. For Each objControl In SelectedControls objControl.Caption = txtCaption.Text Next End Sub While we have created the property page for the FancyCmdButton control, we have yet to connect it to the control. Here are the required steps:
Now that the property page is connected to the control, you can use it to set the controls propertiesin this case, there is only one property. To try it out, you must first close the Property Page designer. Just like a control, a property page must be in run mode to be available to its connected control. Then, double-click on Form1 in the Project box to display the form for the test program. Right-click on the FancyCmdButton control on the form and select Properties from the pop-up menu. The property page we designed will be displayed, as shown in Figure 17.12. Change the Caption property on the property page, then click on either OK or Apply. Youll see the new property reflected immediately on the control on the test form. Compiling The ActiveX ControlAs long as your ActiveX control is part of a Visual Basic project, it can be used within that projectbut thats all. To make it available to other applications, you must compile it into an OCX file. In this section, Ill show you how to compile the demonstration ActiveX control that we created and how to use the compiled version in your project. To compile the ActiveX control, follow these steps:
Once you have compiled the ActiveX control into an OCX file and removed the ActiveX project from the project group, Visual Basic will automatically switch to using the compiled version in the test project. Youll see that the icon for the ActiveX control is still displayed in the Visual Basic Toolbox. You can add other instances of the control to the projects form, access its property page, and so on. Using The ActiveX Control In Other ProjectsWhen you start a new Visual Basic project, you will not automatically have access to the ActiveX controls you have created. To add them to the Toolbox, you must select Components from the Project menu to display the Components dialog box (see Figure 17.13). Place a check mark next to the control or controls you want available in your project (controls you created are listed by the name you assigned). In the case of the demonstration control, it will be listed as Fancy Command Button. At that point, the control will be available to your project, just as any other ActiveX control.
Distributing ActiveX ControlsIf you have poured a lot of effort into designing an ActiveX control, you may want to distribute it to other users. Maybe you can even sell a few copies. Fortunately, the complexities of distribution are handled nicely by the Visual Basic Package and Deployment Wizard, covered in Chapter 26. Simply specify the ActiveX control project, and the wizard will walk you through the steps of creating the required distribution files/diskettes. Using ActiveX Controls On The WebBefore beginning this subject, let me warn you that I will be providing only the most rudimentary coverage of using ActiveX controls on the Web. Its a complex topiccertainly not something that you should attempt unless you are quite familiar with various aspects of the Web and Web-site management. Even so, I want to cover the basics, so you will at least have a start. Youll need a little Internet knowledge to follow this section, however.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |