17 06 2JLLAXLDWXJM55VD3UBJTGC2IPC6M3UKB3LL42Y




Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:ActiveX Controls
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive 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! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




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 control’s 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 Box’s 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 page’s 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 page’s 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! Don’t 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:


1.  Double-click on FancyCmdButton in the Project window to open the designer.
2.  In the Property list, scroll down to the PropertyPages property. The current setting of this property will be (none).
3.  Click on the button with the ellipsis (...) to display the Connect Property Pages dialog box (see Figure 17.11). The dialog lists the FCBGeneral page that we just designed, as well as three standard property pages that Visual Basic makes available to you.
4.  Click on the FCBGeneral property page name to display a check mark in the box next to it, then click on OK.

Now that the property page is connected to the control, you can use it to set the control’s properties—in 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. You’ll see the new property reflected immediately on the control on the test form.
Compiling The ActiveX Control
As long as your ActiveX control is part of a Visual Basic project, it can be used within that project—but that’s all. To make it available to other applications, you must compile it into an OCX file. In this section, I’ll 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:


Figure 17.11  Connecting a property page to the FancyCmdButton control.


Figure 17.12  Displaying the property page for the FancyCmdButton control.


1.  Be sure all parts of the project group are in design mode.
2.  In the Project window, click on AXCtrlDemo to make it the active project.
3.  Open the File menu and select Make AXCtrlDemo.OCX. Visual Basic displays the Make Project dialog box. If you want the OCX file in a different folder, select it here. You can accept the default name for the OCX file, which is the same as the project name (AXCtrlDemo). You can also assign a different name, such as FancyCmdButton, if you wish.
4.  Click on OK. Visual Basic will compile the project. No message is displayed upon completion, but if you look in the specified folder, you will find the OCX file.
5.  On the File menu, select Remove Project to remove the ActiveX control project from the project group. Visual Basic will display a warning message, because the control is referenced from another part of the project group—but that is okay.

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. You’ll 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 project’s form, access its property page, and so on.

Using The ActiveX Control In Other Projects
When 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.


Figure 17.13  Making an ActiveX control available in your project with the Components dialog box.

Distributing ActiveX Controls
If 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 Web
Before beginning this subject, let me warn you that I will be providing only the most rudimentary coverage of using ActiveX controls on the Web. It’s a complex topic—certainly 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. You’ll need a little Internet knowledge to follow this section, however.




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. Read EarthWeb's privacy statement.



Wyszukiwarka

Podobne podstrony:
Cennik kotlow 2013 17 06 2013
Automatyka(000507) 2008 17 06
Suchodół techno 17 06 2009
ClusteringHW 3 17 06
EGZAMIN Z GINEKOLOGII I POŁOŻNICTWA 17 06 2013
WSM 06 17 pl(2)
06 11 09 (17)
2015 06 23 Dec nr 241 MON Dywizjon Plot 17 Wlkp BZ odznaki

więcej podobnych podstron