How to Create an ActiveX Control in VB
ActiveX controls are Microsoft's answer to the limited security model of JavaScript. JavaScript is a powerful language that is limited for security purposes to not have access to the client computer on which it runs. ActiveX fills that void by allowing users on Internet Explorer to download and run embedded programs, called ActiveX controls, that have full access to the client computer to save and load files, for example. This makes ActiveX both powerful and dangerous.
Instructions
-
-
1
Create a new Class Library Project by clicking "File > New > New Project" then choosing "Visual Basic Projects" in the left navigation pane, and finally "Class Library" from the right hand window.
-
2
Add a User Control by right clicking on the project name in the navigation pane, and selecting "Add > User Control."
-
-
3
Add a textbox to the user control by dragging it from the Toolbox onto the gray, User Control area. Rename it "txtUserText".
-
4
Double click the user control to display the source code.
-
5
Copy and paste the following code into the top of your User Control class:
Public Property UserText() As [String]
Get
Return mStr_UserText
End Get
Set
mStr_UserText = value
'Update the text box control value also.
txtUserText.Text = value
End Set
End Property -
6
Copy and paste the following code above the UserControl class to create a new interface:
Public Interface AxMyControl
Property UserText() As [String]
End Interface -
7
Add the following lines directly under the class declaration for your control:
Inherits System.Windows.Forms.UserControl
Inherits AxMyControl -
8
Click "Project > Build" to create the ActiveX assembly, ready to embed in your web site.
-
1
Tips & Warnings
ActiveX is a microsoft technology that only works on the web with Internet Explorer. If you have a public facing website, be aware that only users of Internet Explorer will be able to use your ActiveX control.