ActiveX Control Tutorial - Part 5, Page 4
Getting it on the Net
If you have the urge, you can even get your control on the Internet. How?
Well, you might want to test it within Internet Explorer (IE) first. Whilst in your ActiveX control project, try selecting Project, Properties then clicking the 'Debugging' tab. Choose the 'Start component:' option and select your control. Then click OK and press F5 to run your control within IE.
Whilst running in the browser an ActiveX 'container' - click on View, Source. What do you see? Does this make sense after reading the section on class IDs?
To create an Internet setup package for your control, run the Package and Deployment wizard as earlier but this time select 'Internet Setup' as opposed to 'Standard Setup' and follow the on-screen instructions.
Adding an About Box
Ever noticed how some controls have a really cool 'About' box that you can activate by clicking on the ellipsis at the top of the Properties window?
Well, you can add your own by including the following code in your control:
Public Sub About()' load your about form, whatever it may befrmAbout.ShowEnd Sub
After this, select Tools, Procedure Attributes. Select 'About' from the drop-down list, then click on the 'Advanced>>' button. From the procedure ID drop-down, select the 'AboutBox' option. This tells the Properties window that this piece of code displays your About box.
And that's it!
Top Tip: Don't forget that you don't have to display a form as your About box, it could just be as simple as a message box (MsgBox). Still, a form does look groovier!
Let's Get Multiple
You may have already noticed, but some OCX files pack more than just one simple control. Oh yes. Take the 'Microsoft Windows Common Controls' that ship with Visual Basic. That includes a whopping nine separate controls.
So how can you have more than one control in each ActiveX control project? Simple. Just click Project, Add User Control. This adds another 'workspace' to your project, which is the 'form' of your control.
And then continue developing just as you would normally. When you finally compile the control and add it to a test project, you'll notice two icons in the toolbar one for each 'workspace' (User Control) in your project.
Protecting your Control
So, you've created your own supercool control and want to release it to the world - but are slightly worried about devious developers devouring dodgy yet delectable distributions? Or in English, you're worried about piracy?
No problems. Although I've never personally needed to go this far, there are numerous programs on the market to help you create 'Trialware', a time- or feature-limited product that gives developers a taste of your talents.
One such example is Soft Sentry 3, a trial of which is available for download from www.twenty.com
Retrieving the Control Name
Ever wondered how the Text Box control inserts its Visual Basic name into the Text property each time you add one to a form such as Text1, Text2 and so on?
It's easy to do. Simply grab the DisplayName property of the Ambient object, like this:
Text1.Text = Ambient.DisplayName
Don't forget, the Ambient object contains information about your control's environment, such as the BackColor and Font of the form it resides on. It's a good idea to make your control be a good little boy - and use these properties to set it's own BackColor and so on.