Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add manually COM Object in a Form

Posted on 2007-12-07
4
Medium Priority
?
771 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 9

Accepted Solution

by:
sognoct earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.

604 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