• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 801
  • Last Modified:

Add manually COM Object in a Form

Add  automatically a COM object in a form is very simple click on the object and put in the form using visual studio. But how to do the same thing manually? for example I want to add the COM object in a form only when an event occur. I tried to copy the same code that I found in the Form1.Designer.vb inside the Form1_Load event but I have errors and I do not know how to do.
Here the code in the form designer:
Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.AxCamImage1 = New AxATLCAMIMAGELib.AxCamImage
        CType(Me.AxCamImage1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'AxCamImage1
        '
        Me.AxCamImage1.Enabled = True
        Me.AxCamImage1.Location = New System.Drawing.Point(45, 28)
        Me.AxCamImage1.Name = "AxCamImage1"
        Me.AxCamImage1.OcxState = CType(resources.GetObject("AxCamImage1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.AxCamImage1.Size = New System.Drawing.Size(192, 192)
        Me.AxCamImage1.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.AxCamImage1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.AxCamImage1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
    End Sub  

How can i do the same thing in the event Load
I hope is clear my question thank You very much
0
mpbejo
Asked:
mpbejo
  • 3
1 Solution
 
sognoctCommented:
exactly in the same way of the designer

but ovviously you must delete the object from the designer first ...



private AxCamImage1 as  AxATLCAMIMAGELib.AxCamImage
 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AxCamImage1 = New AxATLCAMIMAGELib.AxCamImage
  AxCamImage1.Enabled = True
        AxCamImage1.Location = New System.Drawing.Point(45, 28)
        AxCamImage1.Name = "AxCamImage1"
        AxCamImage1.OcxState = CType(resources.GetObject("AxCamImage1.OcxState"), System.Windows.Forms.AxHost.State)
        AxCamImage1.Size = New System.Drawing.Size(192, 192)
        AxCamImage1.TabIndex = 0
        Me.Controls.Add(Me.AxCamImage1)
end sub 

Open in new window

0
 
sognoctCommented:
probably the OcxState must be setted manually with the values inside the resx file of the designer
0
 
mpbejoAuthor Commented:
Hi sognoct thank You for help,
this solution is perfect if You use .net framework but if You use .net compact framework You receive this message:
The targeted version of the .NET Compact Framework does not support latebinding
Do You have idea to solve this problem
Thank You
0
 
sognoctCommented:
I always use ctype of objects, i prefer programming with

option strict on
option explicit on

Visual Studio itself resolves latebinding suggesting how to do the correct ctype
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now