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)'.

CAUSE

Visual 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.

WORKAROUND

To 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:
  1. In Visual Basic 6.0, start a new ActiveX Control project.

    By default, UserControl1 is created.
  2. On the Properties window, locate BackColor, and then click to select Highlight from the list.
  3. On the Project menu, click Project1Properties.
  4. On Project1Properties, click to select the Require License Key option.
  5. On the File menu, click Make Project1.ocx.
  6. 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:
  7. 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.
  8. In Customize Toolbox, click the COM Components tab, and then click Browse.
  9. Locate the Project1.ocx ActiveX control file, and then click Open.
  10. From the toolbox, drag UserControl1 to Form1.
  11. On the Project menu, click Add Windows Form.
  12. From the toolbox, drag a Button control to Form2.
  13. On the View menu, click Code.
  14. Add the following code as the first line of the code:
    Imports System.Resources
  15. 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)
    
  16. In Solution Explorer, right-click WindowsApplication1, and then click Properties.
  17. Under Startup object, click to select Form2.
  18. On the Debug menu, click Start.
  19. Click Button1 to add the ActiveX control.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. In Visual Basic 6.0, start a new Standard EXE project.

    By default, Form1 is created.
  2. On the toolbox, double-click the CommandButton control.
  3. Add the following code to the Click event of Command1:
    Dim c As Control
    'add the license to the control at runtime
    Licenses.Add "MSComctlLib.Slider", "546-2137-wdfj-dhf"
    'add the control to the form
    Set c = Me.Controls.Add("MSComctlLib.Slider", "MyControl")
    c.Visible = True
  4. Save the project.
  5. Open Visual Studio .NET or Visual Studio 2005.
  6. On the File menu, point to Open, and then click Project.
  7. Locate the Project Name file in the Visual Basic project, and then click Open.
  8. In Visual Basic Upgrade Wizard, click Next three times. In Warning, click Yes.
  9. Click Next to upgrade the project.

    You receive the errors mentioned in the "Symptoms" section of this article.

REFERENCES

For more information, visit the following MSDN Web site:

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kbLicensing kbWindowsForms kbDesigner kbCtrl kbControl kbComCtrls kbprb KB814361 kbAudDeveloper