根据装配动态加载表格 [英] Dynamicaly Load forms depending on assemblies

查看:97
本文介绍了根据装配动态加载表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用接口来加载在其他项目程序集(.dll文件)中编译的表单?有人有一些代码示例.

我目前正在使用Mdi childs 子项[SA]和功能区来开发Windows应用程序,我需要根据接口和反射在文件夹上找到的程序集来动态加载表单.

如果有人有一些代码/示例...,请:/

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 :/

推荐答案

当然可以.您甚至可以在运行时编译某些项目并添加已编译的程序集.没错,可以使用接口来完成.

实际上,在其他程序集中编译"尚不清楚.您可以在定义窗体和/或其他零部件的地方静态引用装配,然后在装配中使用它们.这很简单;您几乎不需要任何代码示例.动态加载程序集比较困难,但不是问题.请参见下面.

我的建议是:永远不要使用MDI;强烈建议不要使用此样式(首先,我的Microsoft引入了MDI),另请参见:
在WPF中使用MDI窗口的问题 [ ^ ],
提供错误的MDIContainer [创建使用可重载插件的WPF应用程序... [ ^ ],
AppDomain拒绝加载程序集 [ http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [ ^ ].

这是针对表单的选项卡式UI的最简单演示:
带标签的MDI子表单 [多标签Web浏览器 [在WPF中标记的MDI [ WPF C#功能区控制库 [类似于FireFox的标签控件 [
—SA
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.



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


您可能还想看看反射. [
You might also want to look at reflection. This[^] excellent article describes this when you want a form to be loaded in unreferenced assemblies.


这篇关于根据装配动态加载表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆