Solved

Add manually COM Object in a Form

Posted on 2007-12-07
4
727 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 157
VB .NET application would like equitable cpu usage 3 25
Saveas need to save a copy 16 26
Error in page 3 44
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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.

929 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

14 Experts available now in Live!

Get 1:1 Help Now