Visual Basic .NET or Visual Basic 2005 does not support adding ActiveX controls and licenses at run time (814361)
The information in this article applies to:
- Microsoft Visual Basic 2005
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
SYMPTOMS Your Microsoft Visual Basic 6.0 Standard EXE project adds a
control, and then adds a license to the control at run time by using the Licenses.Add method. When you upgrade the project to Visual Basic .NET or Visual Basic 2005, you
may receive the following errors: Name 'Licenses' is
not declared. Value of type 'String' cannot be
converted to 'System.Windows.Forms.Control'. Too many arguments to 'Public Overridable Overloads Sub Add(value
As System.Windows.Forms.Control)'. CAUSEVisual Basic 6.0 uses the Licenses.Add method to add licenses to the controls at run time. Visual Basic
.NET or Visual Basic 2005 does not support adding licenses and ActiveX controls at run time that are
not added to the project at design time. Therefore, you receive errors when you
upgrade the project to Visual Basic .NET or Visual Basic 2005.WORKAROUNDTo work around this problem, add the licensed ActiveX
control to a Windows form. This creates an OcxState object that contains the license key and wrapper classes for the
ActiveX controls. Use the generated OcxState with any controls that you create at run time. To do this, follow
these steps:
- In Visual Basic 6.0, start a new ActiveX Control project.
By default, UserControl1 is created. - On the Properties window, locate
BackColor, and then click to select Highlight
from the list.
- On the Project menu, click
Project1Properties.
- On Project1Properties, click to select the
Require License Key option.
- On the File menu, click Make
Project1.ocx.
- In Visual Studio .NET, start a new Windows application by
using Visual Basic.
By default, Form1 is
created.
Note You must change the code in Visual Basic 2005. By default, Visual Basic creates two files for the project when you create a Windows Forms project. If the form is named Form1, the two files that represent the form are named Form1.vb and Form1.Designer.vb. You write the code in the Form1.vb file. The Windows Forms Designer writes the code in the Form1.Designer.vb file. The Windows Forms Designer uses the partial keyword to divide the implementation of Form1 into two separate files. This behavior prevents the designer-generated code from being interspersed with your code.
For more information about the new Visual Basic 2005 language enhancements, visit the following Microsoft Developer Network (MSDN) Web site:
For more information about partial classes and the Windows Forms Designer, visit the following MSDN Web site:
- Click Customize Toolbox on the
Tools menu.
Note If you are using Visual Studio .NET (2003), click
Add/Remove Toolbox Items on the Tools
menu.
Note If you are using Visual Studio 2005, click
Choose Toolbox Items on the Tools
menu. - In Customize Toolbox, click the
COM Components tab, and then click
Browse.
- Locate the Project1.ocx ActiveX control file, and then
click Open.
- From the toolbox, drag UserControl1 to
Form1.
- On the Project menu, click Add
Windows Form.
- From the toolbox, drag a Button control to
Form2.
- On the View menu, click
Code.
- Add the following code as the first line of the code:
Imports System.Resources - Add the following code to the Button1_Click event handler:
Dim resources As ResourceManager = New ResourceManager(GetType(Form1))
'create the instance of the ActiveX control
Dim AxLicCtl1 As New AxProject1.AxUserControl1()
'use the OcxState generated
AxLicCtl1.OcxState = resources.GetObject("AxLicCtl1.OcxState")
'add the control to the form at run time
Me.Controls.Add(AxLicCtl1)
- In Solution Explorer, right-click
WindowsApplication1, and then click
Properties.
- Under Startup object, click to select
Form2.
- On the Debug menu, click
Start.
- Click Button1 to add the ActiveX
control.
STATUS This
behavior is by design.REFERENCESFor more information, visit the following MSDN Web site:
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbvs2005swept kbvs2005applies kbLicensing kbWindowsForms kbDesigner kbCtrl kbControl kbComCtrls kbprb KB814361 kbAudDeveloper |
---|
|