Click here to Skip to main content
14,239,882 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi, Is there any way to load forms compiled in other project assemblies(.dll files) using interfaces ? Has anyone some code example.

I am currently developing a Windows Application using Mdi childs children [SA] and ribbons and I need to dynamicaly load forms depending on assemblies found on folder using Interfaces and reflection.

If anyone has some code / example... Please :/
Posted
Updated 24-May-11 15:36pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

Yes of course. You can even compile some project during run-time and add compiled assemblies. And right, it can be done using interfaces.

Actually, "compiled in other assemblies" is not clear. You can statically reference the assemblies where you define forms and/or other components and than use it in your assembly. This is straightforward; you hardly need any code samples. Dynamically loading assemblies is more difficult but not a problem. Please see below.

My advice would be: never use MDI; this style is highly discourages (first of all, my Microsoft where MDI was introduced), see also:
Question on using MDI windows in WPF[^],
MDIContainer giving error[^].

Now, about dynamically loaded assemblies which you can use as plug-ins. Please see my sketch of plug-in functionality in my past answers:
Create WPF Application that uses Reloadable Plugins...[^],
AppDomain refuses to load an assembly[^].

Don't think it's very difficult. You can ignore everything related to reloadable plug-ins and Application Domain. It depends though. It you really want to unload your plug-ins, you will need all that. It's not too hard to implement but will need considerable effort in the first stage of it. Better do prototyping on highly simplified model first.

[EDIT — follow-up discussion on non-MDI UI, Tabbed UI]

Here is one more link against MDI: http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^].

This is the simplest demonstration of Tabbed UI for forms:
Tabbed MDI Child Forms[^].

See some more (some for WPF, some for Forms, the techniques are very close):
Multi Tab WebBrowser[^],
Tabbed MDI in WPF[^],
WPF C# Ribbon Control Library[^] (complicated),
FireFox-like Tab Control[^].

You will be able to find a lot more is you search CodeProject articles or Google. If I were you I would just take a TabControl and implemented it from scratch. Add main menu and status bar to an empty main form first. Add a TabConrol, make its Dock = DockStyle.Fill. That's all the framework.

What you had as child Forms will go to the Tab pages (their contents will), during design time and/or run time. Much easier then MDI children, I tell you. Same thing about your plug-ins providing content controls.

—SA
   
v2
Comments
sairam.bhat 25-May-11 2:20am
   
My +5
   
Thank you, Sairam.
--SA
soulprovidergr 25-May-11 12:36pm
   
Thanks For the answer. I found the way Thanks to the last 2 links that you provided. But i dont understand why not to use mdi. I don't know(yet) any other way to make folding forms inside a main window :/
Sergey Alexandrovich Kryukov 25-May-11 12:56pm
   
Good if you found a way to plug-ins. It should mean you have a sufficient level (many Inquirers pretended they would do it but gave up even on the simplest aspects of Reflection, processes, etc. when they learned what's involved).

Now, some developers said "there is nothing wrong with MDI", but why risk it? I mean, the negative reaction to MDI is not just my personal preference; this vision of quite common vision, a fact of social life. (I'll put one more reference on disadvantages -- Wikipedia.) So, even if only a part of users would shout "what the hello" -- why would you need it.

Most used Tabbed interface based on TabConltol does it all nicely. Instead of child MDI window you will have an MDI tab panel, that's all. Implementation is actually way easier. Let me see if I find some samples...
--SA
Sergey Alexandrovich Kryukov 25-May-11 13:10pm
   
OK, see my updated solution. Feel free to ask your follow-up questions if you need to.

Thanks for accepting this answer.
Good luck,
--SA
soulprovidergr 26-May-11 9:08am
   
Thanx For The links... Reading something New is always welcome :D
   
You're welcome.
Good luck, call again,
--SA
Rate this:
Please Sign up or sign in to vote.

Solution 2

You might also want to look at reflection. This[^] excellent article describes this when you want a form to be loaded in unreferenced assemblies.
   
Comments
soulprovidergr 26-May-11 9:09am
   
Thanx for the Link.
First Solution Gave me the big picture.
I googled for some help.
Your Solution gave the last part of missing pieces of my puzzle!! :) thanks!
Abhinav S 26-May-11 10:19am
   
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100