惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
C
Check Point Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
博客园 - 司徒正美
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
V
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
O
OpenAI News
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
I
InfoQ
D
Docker
P
Palo Alto Networks Blog
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
博客园 - Franky
B
Blog
Scott Helme
Scott Helme
博客园 - 叶小钗
D
DataBreaches.Net

博客园 - 中尉

开源后的.Net 如何选择使用 创建多个Oracle数据库及相应的实例 DB2和Oracle区别 宝化项目结题 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 VB.NET and C# Comparison Java and C# Comparison 小小议下WINFORM应用框架开发(一) 整合TextBox与Label 创建新控件--EFLabelText 摩斯密码 - 中尉 用户中心 - 博客园 用户中心 - 博客园 ProC连接Oracle 关于博文转载 如何成为优秀的软件人才 休息下 关于系统设计分层
从DLL中加载启动窗体
中尉 · 2008-07-13 · via 博客园 - 中尉

在一般应用程序中,经常有个主登陆窗体,做验证及其他等操作。为保持公司项目(或是产品)的一致性,常将其固化,在项目开发时候直接引用之即可。下面做个简单的事例程序。具体创建工程,添加项目过程略过,下面是创建好以后的解决方案图:

主要步骤:
1: 在类库项目Main中要添加对System.Drawing和System.Windows.Forms的引用;
2:在类库项目Main的属性中改变其输出类型为Windows 应用程序,输出路经为 ..\;
3:在类库项目Test的属性中改变其输出路经为..\;

MainStart.cs基本代码实现如下:

 1using System;
 2using System.Drawing;
 3using System.Collections;
 4using System.ComponentModel;
 5using System.Windows.Forms;
 6using System.Data;
 7using System.Diagnostics;
 8using System.Reflection;
 9using System.Threading;
10using System.Xml;
11using System.IO;
12
13namespace Main
14{
15    /// <summary>
16    /// MainStart 的摘要说明。
17    /// </summary>

18    public class MainStart
19    {
20        public MainStart()
21        {
22            //
23            // TODO: 在此处添加构造函数逻辑
24            //
25        }

26
27        [STAThread]
28        static void Main(string[] args) 
29        {
30
31            Assembly a;
32            Type b;
33            Object obj = null;
34            string dll_path = " ";
35            Type[] mytypes;
36            try 
37            {
38                dll_path =Path.GetFullPath("."+ "\\Test.dll"
39
40                a = Assembly.LoadFrom(dll_path);
41  
42                try 
43                {
44                    mytypes = a.GetTypes();
45                }
 
46                catch 
47                {
48                }

49
50                b = a.GetType("Test.MainForm");
51                obj = Activator.CreateInstance(b);        
52                Application.Run((Form)obj);  
53            }
 
54            catch (Exception e) 
55            {
56        
57                Console.WriteLine(e.ToString());
58                if (obj != null
59                {
60                    ((Form)obj).Close();
61                }

62                return;
63            }

64
65        }

66
67    }

68}

4:将Main做为启动项目。编译运行效果如下: