Creating Classes & ActiveX Controls

Using classes and controls

To use a control that someone else created (and compiled to an OCX file) in a project, you add a reference to it by checking the box next to it on the Components list (Project|Components). You then select its icon on the toolbox and draw where you want it to go. Some controls are visible during run time (like the text box), others are only visible at design time (like the common dialog control, and the Image List control). Once you have added them to a form, you can change their properties at design-time using the properties window. You can also change properties at runtime, and call methods (the name for 'public' procedures in a control/class). To use the controls properties and methods at runtime, you use something like this:

FormName.ControlName.Property = Value
FormName.ControlName.Method (Param1, Param2...)

To use a class in a project that someone else created (and compiled to an DLL file) in a project, you add a reference to it by checking the box next to it on the References list (Project|References). Normally, classes in a DLL are 'multi-use', which means you can have more than one instance of it in your project. This also means that you need to create it, like below.

Dim clsClass As New DllName.ClassName

If the DLL Class was specified as global, then you can only have one 'instance', and the dll functions will be available like any other VB function, and is loaded into the memory when the project first executes. To use the functions and properties, you simply enter its name and parameter:

FunctionName (Param1, Param2...)
PropertyName = Value

After this statement To use its functions and properties, you then ues this syntax:

clsClass.Property = Value
clsClass.Method (Param1, Param2 ...)

The next few sections will show you how to create your own classes and controls, and how to use properties, methods, and enums.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Nine people can't make a baby in a month.” - Fred Brooks