|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
For example, we can call the calculator controls Calculate method when the user clicks that control, like this:
Private Sub CalculatorControl1_CalculatorClick()
CalculatorControl1.Calculate
End Sub
In this way, weve 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 books accompanying CD-ROM.
Adding Design Time Property PagesThe Testing Department is calling again. Cant 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 youve added properties to an ActiveX control, you can use the Property Page Wizard to add property pages for those properties. Lets see an example. Here, well add a set of property pages for our ActiveX calculator control that weve 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. Heres 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 well set up a separate property page for each, as shown in Figure 20.18.
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 youve 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.
Finally, click Next to go to the Property Page Wizards 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 were 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 books accompanying CD-ROM.
Creating An ActiveX DocumentThe Testing Department is calling again. The ActiveX controls youve 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. Lets 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 DLLssee the next topic for a discussion of the difference). This creates a new ActiveX document in Visual Basic, as shown in Figure 20.21.
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 thats run when the ActiveX document is first opened. Because were drawing from the Initialize event handler, set the documents AutoRedraw property to True (just as you would for a form). Lets 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 documents specification, a VBD file, into the browser, which (if it supports ActiveX documents) runs the documents EXE file or adds the documents DLL file to its own process, as shown in Figure 20.22.
Thats all there is to it. Now weve created our first ActiveX document. Still, not much is going on here yet. In the following topics, well develop our ActiveX documents further.
|
|
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. |