Azmodan
asked on
Dynamic Control Creation
I would like to dynamically load a control, a control that I don;t know of at desgin-time.
In VB6 there was a Controls.Add were u suplied a ClsID and the control was loaded.
There must be something like this in C#, a way to load at run-time a dll with a UserControl in it and be able to put it on screen.
In VB6 there was a Controls.Add were u suplied a ClsID and the control was loaded.
There must be something like this in C#, a way to load at run-time a dll with a UserControl in it and be able to put it on screen.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you including a refernce to simplex.dll in your project (or including it in the csc command if you're not using vs.net)? You need to do this - or register simplex.dll in the GAC.
ASKER
No,thats the whole point... to load a control at runtime!!
So, just with code, not by adding it to the references at design-time.
Can this be done without the GAC? By giving it the Asembly, or adding it's reference at run time...
So, just with code, not by adding it to the references at design-time.
Can this be done without the GAC? By giving it the Asembly, or adding it's reference at run time...
If your assembly that you want to use dynamically isn't in the GAC, then it must be in the same directory as the calling application. Also - don't include the path or .dll extension in the CreateInstance() call.
ASKER
yeah..that seams to work. If i don't put the .dll in its name, it takes it from the current directory.
But... the CreateInstance returns an object or ObjectHandle. If I want to put the loaded control on the form, I need to use Controls.Add... which takes a Windows.Forms.Control. And the system won;t cast object to control. Is there a way?
But... the CreateInstance returns an object or ObjectHandle. If I want to put the loaded control on the form, I need to use Controls.Add... which takes a Windows.Forms.Control. And the system won;t cast object to control. Is there a way?
ASKER
no..i got it
ObjectHandle.Unwrap.. returns a castable pointer. And it can be casted to Forms.Control
ObjectHandle.Unwrap.. returns a castable pointer. And it can be casted to Forms.Control
ASKER
10x
i'll figure out the details
i'll figure out the details
ASKER
hdlSample=Activator.Create
raises an exception: File or assembly name C:\Simplex.dll, or one of its dependencies, was not found.
what am i doing wrong?