Solved

Add manually COM Object in a Form

Posted on 2007-12-07
4
725 Views
Last Modified: 2013-11-26
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
Comment
Question by:mpbejo
  • 3
4 Comments
 
LVL 9

Accepted Solution

by:
sognoct earned 500 total points
ID: 20426178
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
 
LVL 9

Expert Comment

by:sognoct
ID: 20426183
probably the OcxState must be setted manually with the values inside the resx file of the designer
0
 

Author Comment

by:mpbejo
ID: 20426247
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
 
LVL 9

Expert Comment

by:sognoct
ID: 20426334
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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now