Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dynamic Control Creation

Posted on 2002-07-02
8
Medium Priority
?
233 Views
Last Modified: 2010-04-15
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.
0
Comment
Question by:Azmodan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 4

Accepted Solution

by:
kpkp earned 200 total points
ID: 7124230
sounds like you need to use the Activator.CreateInstance method...

check out

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemActivatorClassCreateInstanceTopic.asp
0
 

Author Comment

by:Azmodan
ID: 7124675
yes.this seems to be the way to go, but i couldn;t make it work

hdlSample=Activator.CreateInstance("C:\\Simplex.dll","Simplex.UserControl1");

raises an exception:  File or assembly name C:\Simplex.dll, or one of its dependencies, was not found.

what am i doing wrong?
0
 
LVL 4

Expert Comment

by:kpkp
ID: 7124705
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Azmodan
ID: 7124739
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...

0
 
LVL 4

Expert Comment

by:kpkp
ID: 7124917
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.
0
 

Author Comment

by:Azmodan
ID: 7126341
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?
0
 

Author Comment

by:Azmodan
ID: 7126351
no..i got it
ObjectHandle.Unwrap.. returns a castable pointer. And it can be casted to Forms.Control
0
 

Author Comment

by:Azmodan
ID: 7126473
10x

i'll figure out the details
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question