You use System Reflection to dynamically load a control. If the DLL is named ‘SpecControls.DLL’ and the class you
want is ‘SpecControls.ColorControl’, then use this code.
[C#]
// load the assembly
System.Reflection.Assembly assembly = Assembly.LoadFrom('SpecControls.DLL');
// get the type
Type t = assembly.GetType('SpecControls.ColorControl');
// create an instance and add it.
//
Control c = (Control)Activator.CreateInstance(t);
parent.Controls.Add(c);
[VB.NET]
’ load the assembly
Dim assembly1 As System.Reflection.Assembly = Assembly.LoadFrom('SpecControls.DLL')
’ get the type
Dim t As Type = assembly1.GetType('SpecControls.ColorControl')
’ create an instance and add it.
’
Dim c As Control = CType(Activator.CreateInstance(t), Control)
parent.Controls.Add(c)
Share with