Live Chat Icon For mobile
Live Chat Icon

How do I dynamically load a control from a DLL

Platform: WinForms| Category: Controls

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.

	// 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);

	 ’ 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) 

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.