Sie sind auf Seite 1von 7

Tutorial 5: Building a Hello World ActiveX Control in VB

This set of instructions will show you how to build, test and package a trivial ActiveX control. The control has no code attached to it: it simply displays some text saying ' ello !orld'.

Download

ello!orld control plus test program

Step 1. Building an ActiveX Control Pro ect


"tart #$ %rom the %ile &enu, select 'ew (ro)ect "elect ActiveX *ontrol from the dialog box.

Step !. "a#ing $our Control Pro ect


%rom the (ro)ect &enu, select (ro)ect+ (roperties ,n the dialog box, change the (ro)ect 'ame and (ro)ect description as shown below. This will determine how your 'friendly' name of your component is displayed later on, as well as the name of your compiled .ocx.

Step %. "a#ing $our actual control

,n the pro)ect explorer window, select -ser*ontrol+. Then change the 'ame (roperty for user control + to ello!ord+. .our window should look like the one below. Original Renamed

Step &. Building $our control


/rop a label into the *ontrol -sing the 0abel properties, change its caption to 1 ello !orld1 and its font to +2 point *reate a +3x+4 bitmap 5using &icrosoft paint6 that has some kind of descriptive image 5you can )ust compose it by writing the letters !6. %rom the ello!orld -ser*ontrol properties, point the Toolbox$itmap to that bitmap. ,t will eventually appear in the Toolbox on the left 5rather than the generic toolbox control image, shown greyed out on the bottom of the left pane below6.

Step 5. Saving $our control

This is probably a good time to save the pro)ect, )ust in case7 "ave it in a folder called 5say6 ello!orld#+

Step '. Te(ting $our control )$ two #et*od(


'ow we will test this simple control via two methods. The first method uses ,nternet 8xplorer. ,f you click the play button, #$ will start ,nternet 8xplorer, and you will see your control in it. The second method for testing a control uses #$ directly. %rom the %ile menu, select Add (ro)ect and then select the "tandard 8X8 icon 5the dialog box is the same as the one already seen in "tep +6 %rom the (ro)ect explorer, right9click on (ro)ect+5(ro)ect+6 to raise the context menu, and select '"et as "tartup'. %rom now on, when you press the play button it will start this program instead of using ,nternet explorer. *lose the form containing your hello world control. and then raise the (ro)ect+ %orm. .ou will see an icon in the bottom of the toolbar: its tooltip will say ello!orld+. "elect this, and drop it into the form. .our window should look something like the one below. %eel free to browse the properties of your ello!orld control in the (roperties window: you will see that its properties is not a label7 :ather, these are the default properties that every ActiveX control made in #$ have. ;ust for fun, add a few more ello!orld controls into your form window. The nice thing about controls is that you can have lots of them7

Step +. Te(ting t*e pro ect

Test the program by hitting play. ,t should bring up the following window.

Step ,. Saving t*e pro ect and t*e pro ect group

"ave the pro)ect group 5this is both the control and the sample application you )ust made6. To do this cleanly, when you save create a new folder called 1Test1 under 1 ello!orld#+1 and save everything to that.

Step -. Co#piling $our .CX


Through the pro)ect explorer, close (ro)ect+ and open up your ello!orld control again. *ompile your control by selecting '&ake *, ello!orld+.ocx' from the file menu. "ave it in your ello!orld#+ folder. *lose down #$

Step 1/. Te(ting $our .CX 0ro# a new VB pro ect.


"tart a new version of #$, and create a new .exe pro)ect. "elect *omponents from the (ro)ect menu, as shown below. "croll the list until you find *, ello !orld #ersion +. *heck the checkbox, and then <k. This will add the hello world control icon to your controls window. :epeat "teps = and >.

Step 11. Pac1aging $our .CX

$ecause of security settings on our machines, we cannot use the standard packaging properties as it will not register your component correctly. !e will show you how to do this in lab. <nce it is done, your control will be available to any #$ program on that machine.

Das könnte Ihnen auch gefallen