17 02 ZZQJ2ZPLR5DUBEYI6VWZHEEW6JBYJWHFYBVEPPQ




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 next step is to set some of the project properties. Select Project1 Properties from the Project menu to display the Project Properties dialog box (shown in Figure 17.2). Display the General tab, make the following entries, then close the dialog box:


•  Project name—AXCTRLDEMO is the name that will be assigned to the final compiled OCX file.
•  Project description—Fancy Command Button is the description users will see when they use the OCX control in other projects.


Figure 17.2  The Project Properties dialog box.

Next, you need to change the Name property of the control itself. Be sure that the control is selected in the Designer window, as indicated by handles around its periphery. In the Properties window, find the Name property and change it to FancyCmdButton. This name will now appear in the designer’s title bar.
Now is a good time to save the project. Select Save Project from the File menu, saving both the control and the project under the default names that Visual Basic suggests: FANCYCMDBUTTON.CTL and AXCTRLDEMO.VBP.
Although the basic framework of the control is in place, it still doesn’t do anything. To add functionality, start by placing a Shape control in the upper left corner of the control. Set its properties as shown in Table 17.1.
Next, add a Label control on top of the Shape control, setting its properties as shown in Table 17.2. Then, reduce the size of the UserControl. The exact size is not crucial—just keep it fairly small. At this stage, your screen will look like Figure 17.3.

Table 17.1 Shape control property settings.



Property Name
Setting

BorderStyle
0 — Transparent

FillColor
&H0000FF00& (or any light green)

FillStyle
0 — Solid

Shape
4 — Rounded Rectangle

Nameshp
Button




Figure 17.3  The FancyCmdButton ActiveX control after adding Shape and Label controls.



Table 17.2 Label control property settings.



Property Name
Setting

BackStyle
0 — Transparent

Name
lblButton

ForeColor
Black

Alignment
2 — Center



The FancyCmdButton control now has all of the subcomponents (other controls) it needs, but that’s not enough, of course. What will it do? How will it appear? Now we need to add the code that will bring our ActiveX control to life.

Our first concern is its appearance. When displayed within a container, we want the Shape control to fill the entire area of the ActiveX control; we also want the Label to be the same width as the Shape control and to be centered vertically. The code to perform these actions should be placed within the UserControl’s Resize event procedure. Display the Code Editing window in the usual manner, then select UserControl in the object list at the top of the window. Finally, select Resize in the Procedure list. Add the code in Listing 17.1 to this event procedure.
Listing 17.1 The UserControl’s Resize event procedure.


Private Sub UserControl_Resize()

‘ Change the position and size of the Shape control
‘ to fill the FancyCmdButton control’s entire area.
shpButton.Move 0, 0, ScaleWidth, ScaleHeight
‘ Make the Label control the same width as the Shape
‘ control and center it vertically.
lblButton.Move 0, (ScaleHeight - lblButton.Height) / 2, ScaleWidth

End Sub


Testing The ActiveX Control
The control is not finished, but it is ready to be tested. How do you test an ActiveX control that you are developing? An ActiveX control cannot run by itself; it needs a container. You have two choices:


•  You can use Microsoft Internet Explorer or another ActiveX-capable browser as the test container. After all, one important use for ActiveX controls is on Web pages, so in some situations testing your control in a browser is perfectly appropriate. If you have not created a separate test project (as described later), and the ActiveX control project is the only one loaded into the Visual Basic environment, then “running” the project will start Internet Explorer and display an instance of the ActiveX control. The control must be compiled first, as described later in the section titled “Compiling the ActiveX Control.” You can try out the control’s capabilities, as well as modify the associated HTML file if you want to test the control in combination with some scripting language elements. These procedures are beyond the scope of this book, although I will touch on them later in the chapter when I cover using ActiveX controls on the Web.
•  You can create a separate Visual Basic project to test the control. This is the preferred testing method, because it provides greater flexibility. Creating a test project is our next topic.

Creating The Test Project
To test an ActiveX control, you need a separate Visual Basic project with a form on which you can place an instance of the control. Rather than starting a separate copy of Visual Basic, you can use one of Visual Basic’s handier features: You can define a project group that contains two or more independent projects. In this case, the ActiveX control will be one project, and the second project will be a standard Visual Basic executable to test the ActiveX control.
To create a project group, select Add Project... from the File menu, then select Standard EXE as the project type. You’ll now have two designers open: one for the ActiveX control project and one for the Standard EXE project you just created. Both projects will be listed in the Project window, as shown in Figure 17.4. Next, save the project group by selecting Save Project Group from the File menu. Use the file names given here (the extensions are added automatically by Visual Basic):

Figure 17.4  A Visual Basic project group can contain two or more independent projects.


•  Form—TestAXCtl_Form1.frm
•  Project—TextAXCtl.vbp
•  Project group—TestAXCtl.vbg

Running The ActiveX Control At Design Time
You may think that the heading of this section makes no sense; didn’t I just say that an ActiveX control cannot run by itself? Yes, but now I am using run in a different sense. An ActiveX control does not run in the same sense as a standard Visual Basic executable. When an ActiveX control “runs,” it makes itself available only for insertion into other projects. This is exactly what we want: to run the ActiveX control, so it becomes available to insert onto the test project’s form, while the test project remains in design mode. This is precisely what Visual Basic’s project groups are intended for.



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:
przyklad w dniu 17 02 2012
17 02 2012 emerytury prezentacja[1]id189
ustawa o informatyzacji działalności podmiotów realizujących zadania publiczne 17 02 2005
17 02 S1 W Geom wykr
17 02 S1 W Geom wykr
17 02 Metodyka oceny ryzyka
rodzina 02 17
KPC Wykład (17) 26 02 2013
02 17 Listopad 1992 Wojna na zakładników

więcej podobnych podstron