最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
C# 编译生成dll文件供程序调用的两种方法
时间:2022-06-25 07:44:30 编辑:袖梨 来源:一聚教程网
一、使用vs2017 创建动态dll文件
方法一:
1、新建-项目-类库
2、创建一个.cs文件 写入代码,例如:建立一个Windows窗体
略丑,简单明了。。。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace ClassLibrary1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("调用成功!"); } } }
3、运行文件,就会在Debug目录下生成ClassLibrary1.dll文件
方法二:
或者在已经写好的模块中,选择项目,右键-属性-输出类型处选择类库
最后 右键-重新生成
二、调用ClassLibrary1.dll文件方法
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; using ClassLibrary1; //引入命名空间 namespace 调用DLL { public partial class Fo : Form { public Fo() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form1 f = new Form1(); //实例化对象 调用 f.Show(); } } }
相关文章
- 《航海王壮志雄心》海域探险沉船打捞有什么好的方法可用 06-16
- 《弹壳特攻队》永久不过期的最新可用兑换码合集 06-16
- 《暖雪》终业DLC新流派灵剑修罗开荒有哪些 06-16
- Metaplanet 砸 1.17 亿美元加码比特币!持币量突破 1 万枚、超越 Coinbase 06-16
- 《魔力宝贝:复兴》1~30级主线困难有哪些快速通关方法 06-16
- 《欢乐钓鱼大师》稀有鱼垂钓有哪些方法 06-16