Hi, 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 -
Here is the code for "treeload" function -
Now, after implementing above code I am able to add ActiveX control to tabpages at run-time.
Here is the code that I used -
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 -
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 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 we treeload function returns this object to do some other stuffs with ActiveX control's objects.Now, after implementing above code I am able to add ActiveX control to tabpages at run-time.
Comments
Post a Comment