Click here to Skip to main content
15,887,746 members
Articles / Programming Languages / XML
Technical Blog

How to Add ActiveX Control at Run Time using C#.NET

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
29 Nov 2013CPOL 9.5K   2  
How to Add ActiveX Control at Run Time using C#.NET

Introduction

Recently, I worked on a project where the requirement was to add an ActiveX control dynamically to a UserControl type project. Here, I was trying to add that ActiveX control to multiple tab pages of a tab control.

Here is the code that I used:

C#
for(int i = 0; i < 4; i++)
{
      this.LineTabs.TabPages.Add(i);
      AxTree treeadd = treeload(this.LineTabs.TabPages[i]);
}

In the above code, I am creating four tab pages at runtime and adding ActiveX control "AxTree" to these pages dynamically using function "treeload".

Here is the code for "treeload" function:

C#
private AxTree treeload(TabPage tab)
    {
        AxTree treeobject = new AxTree();
        ((System.ComponentModel.ISupportInitialize)(treeobject)).BeginInit();
        SuspendLayout();
        tab.Controls.Add(treeobject);
        treeobject.Dock = DockStyle.Fill;
        ResumeLayout();
        ((System.ComponentModel.ISupportInitialize)(treeobject)).EndInit();
        return treeobject;
    }

In the above code, you can see that we are passing a tabpage to treeload function. Here in this function, first we created an object of ActiveX control "AxTree". Then we add this object to tab page. Later on, treeload function returns this object to do some other stuff with ActiveX control's objects.

Now, after implementing the above code, I am able to add ActiveX control to tabpages at run-time.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
Software Engineer having hands-on experience with C, C++, C#, .NET, ASP.NET, SQL, Website designing technologies, Joomla CMS, Application development, COM, MFC, Installshield, Installscript project, Basic MSI

http://newapputil.blogspot.in/
http://nvivekgoyal.blogspot.in/

Comments and Discussions

 
-- There are no messages in this forum --