Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


For example, we can call the calculator control’s Calculate method when the user clicks that control, like this:

Private Sub CalculatorControl1_CalculatorClick()
     CalculatorControl1.Calculate
End Sub

In this way, we’ve added a new event to our ActiveX control. The code for the new version of the ActiveX calculator control is located in the activexcalculatorcontrol folder on this book’s accompanying CD-ROM.


TIP:  Another way to set up events in an ActiveX control is to use the ActiveX Control Interface Wizard in the Add-Ins menu (if that wizard does not appear in your Add-Ins menu, select the Add-In Manager item in the Add-Ins menu and add the ActiveX Control Interface Wizard).

Adding Design Time Property Pages

The Testing Department is calling again. Can’t you add property pages to your new ActiveX control? The programmers who use your control are used to setting properties using property pages at design time.

You can add property pages to your control with the Visual Basic Property Page Wizard in the Add-Ins menu. If that wizard does not appear in your Add-ins menu, select the Add-In Manager item in the Add-Ins menu and add the Property Page Wizard. After you’ve added properties to an ActiveX control, you can use the Property Page Wizard to add property pages for those properties.

Let’s see an example. Here, we’ll add a set of property pages for our ActiveX calculator control that we’ve developed in the previous few topics. Start the Property Page Wizard by selecting that item in the Add-Ins menu now; a welcome screen will appear. Click the Next button until you get to the Select The Property Pages screen, as shown in Figure 20.18.

Here’s where you set up the property pages your control will have. You can add property pages with the Add button and name them with the Rename button. In this case, the calculator control only has two properties, Operand1 and Operand2, and we’ll set up a separate property page for each, as shown in Figure 20.18.


Figure 20.18  Creating property pages.

Click Next to go to the next screen, Add Properties, as shown in Figure 20.19. Here you add properties from the list of all the available properties on the left to the property pages you’ve set up. Just click the tab matching the property page you want to add a property to, select the property in the list box at left, and click the right-pointing arrow button to add that property to the property page (or click the left-pointing arrow button to remove a button from a property page). In this way, you can organize which property appears on which page.


Figure 20.19  Adding properties to property pages.

Finally, click Next to go to the Property Page Wizard’s screen labeled Finished and click the Finish button. In this case, this creates two new property page documents, PropertyPage1.pag and PropertyPage2.pag, for your control, and adds them to your project. Save those files to disk and rebuild your control.

Now embed our ActiveX control in another program and open its property pages at design time, as shown in Figure 20.20. Now we’re supporting property pages for custom ActiveX controls.

The code for the example property page files are located in the PropertyPage1 and PropertyPage2 folders on this book’s accompanying CD-ROM.


Figure 20.20  Our control’s custom property pages

Creating An ActiveX Document

The Testing Department is calling again. The ActiveX controls you’ve been building are fine, but what about going on to the next step? How about creating an ActiveX document? You ask, why are ActiveX documents the next step? Because, they say, although ActiveX controls can appear in Web pages, ActiveX documents can be Web pages. That is, an entire Visual Basic form with all its controls can now appear in your Web browser or other application.

Let’s see an example. To create a new ActiveX document, open the Visual Basic New Project dialog box, select the ActiveX document EXE entry, and click on OK (you can create either ActiveX document EXEs or DLLs—see the next topic for a discussion of the difference). This creates a new ActiveX document in Visual Basic, as shown in Figure 20.21.


Figure 20.21  Creating a new ActiveX document.

To get our start with ActiveX documents, just double-click the document and add this code to the Initialize procedure that opens to draw a set of crisscrossing lines and a black box in the center of the document:

Private Sub UserDocument_Initialize()
     Line (0, 0)-(ScaleWidth, ScaleHeight)
     Line (0, ScaleHeight)-(ScaleWidth, 0)
     Line (ScaleWidth / 4, ScaleHeight / 4)-(3 * ScaleWidth / 4, _
         3 * ScaleHeight / 4), , BF
End Sub

This is the procedure that’s run when the ActiveX document is first opened. Because we’re drawing from the Initialize event handler, set the document’s AutoRedraw property to True (just as you would for a form).

Let’s see our new ActiveX document at work in a Web browser (you can use ActiveX documents in other applications that support them, but Web browsers are particularly handy for testing ActiveX documents in an interactive way). Select the Project1 Properties item in the Project menu, and click the Debugging tab in the Project Properties dialog box that opens. Make sure that the option button labeled Start Component is selected (the start component should be given as UserDocument1) and the box labeled Use Existing Browser is checked. Then close the dialog box by clicking on OK, and run the document with the Start item in the Run menu.

Starting the document loads the document’s specification, a VBD file, into the browser, which (if it supports ActiveX documents) runs the document’s EXE file or adds the document’s DLL file to its own process, as shown in Figure 20.22.


Figure 20.22  Opening our new ActiveX document in the Microsoft Internet Explorer.

That’s all there is to it. Now we’ve created our first ActiveX document. Still, not much is going on here yet. In the following topics, we’ll develop our ActiveX documents further.


TIP:  Oh great, you’re thinking, I’ve developed an extensive standard Visual Basic program based on forms, and now I’ve got to convert it into an ActiveX document? Visual Basic includes a wizard to help you in just this case: the ActiveX Document Migration Wizard. Just select that wizard in the Add-Ins menu (if the wizard does not appear in your Add-ins menu, select the Add-In Manager item in the Add-Ins menu and add the ActiveX Document Migration Wizard).


Previous Table of Contents Next


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.