![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
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 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:
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 designers 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 doesnt 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 crucialjust keep it fairly small. At this stage, your screen will look like Figure 17.3.
The FancyCmdButton control now has all of the subcomponents (other controls) it needs, but thats 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 UserControls 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 UserControls Resize event procedure. Private Sub UserControl_Resize() Change the position and size of the Shape control to fill the FancyCmdButton controls 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 ControlThe 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:
Creating The Test ProjectTo 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 Basics 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. Youll 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):
Running The ActiveX Control At Design TimeYou may think that the heading of this section makes no sense; didnt 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 projects form, while the test project remains in design mode. This is precisely what Visual Basics project groups are intended for.
|
![]() |
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. |