All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
超级强大的表单验证代码_JavaScript技术_编程技术
SQL数据库高级教程:学习 SQL Alias(别名)_[SQL Server教程]
php——array,数组学习整理_php资料_编程技术
详解ASP.NET数据读取与填充方式_[Asp.Net教程]
Sql,server,2005的XML最佳实施策略(2)_[SQL,Server教程]
警告!Ajax技术的安全问题不容忽视_.net资料_编程技术
ASP.NET,2.0,AJAX中Webservice调用方法示例_[Asp.Net教程]
漫谈Ajax在ASP.Net中的使用_[Asp.Net教程]
LINQ体验(12)——LINQ,to,SQL语句之对象标识和对象加载_[Asp.Net教程]
C#中MonthCalendar控件应用实例
Reading number is top 10 pictures
So beauty, will let you spray blood2
So beauty, will let you spray blood5
30 beautiful school beauty3
囚犯暴乱了咋办?
西方气质的东方美女3
中国的十元人民币的秘密
Poor doll, hand job was caught the currently in effect by his dad
The world's top ten most beautiful railway station2
Ashlynn Brooke photograph of a group1
Look for from human art net, is good--3
Download software ranking
Call Of Duty2
Be there or be square
Professional killers2 data package
White deer villiage
Tram sex maniac 2 (H) rar bag3
Twenty piece of palm leaf
The cock of the Grosvenor LTD handsome
Proficient in Eclipse
Boxer vs Yellow5
SP3 for SQL2000
qq published in(发表于) 2014/7/11 9:22:00 Edit(编辑)
C#教程:C#调用动态链接库

C#教程:C#调用动态链接库

C#教程:C#调用动态链接库

C#调用动态链接库

下面主要通过一个示例来讲解如何调用动态链接库。

示例

通过调用类库实现简单计算器程序

通过引用类库,使用类库中的相关方法开发一个简单的计算器,运行效果如图1所示。



图1 简单计算器

(1)在菜单栏中选择“项目”/“添加引用”,弹出“添加引用”对话框,在“添加引用”对话框中选择“浏览”选项卡。

(2)通过浏览找到上一节中创建的DLL类库,单击【确定】按钮,将类库添加到项目中,如图2和图3所示。



图2 引用类库



图3 添加DLL类库成功

类库添加成功后,在程序中就可以直接使用了。示例完整代码如下所示。

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using _4_01;

namespace _4_02

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

Operation oper = new Operation();

private void button1_Click(object sender, EventArgs e)

{

switch (comboBox1.Text)

{

case "+":

textBox3.Text = oper.Add(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2. ext)). oString();

break;

case "-":

textBox3.Text = oper.Minus(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)). oString();

break;

case "*":

textBox3.Text = oper.Multiplication(Convert.ToDouble(textBox1.Text), Convert.ToDouble (textBox2.Text)).

ToString();

break;

case "/":

textBox3.Text = oper.Division(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)).

ToString();

break;

}

}

}

}

完整程序代码如下:

★ ★★★★Form1.cs窗体代码文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using _4_01;

namespace _4_02

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

Operation oper = new Operation();

private void button1_Click(object sender, EventArgs e)

{

switch (comboBox1.Text)

{

case "+":

textBox3.Text = oper.Add(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)).ToString();

break;

case "-":

textBox3.Text = oper.Minus(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)).ToString();

break;

case "*":

textBox3.Text = oper.Multiplication(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)).ToString();

break;

case "/":

textBox3.Text = oper.Division(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)).ToString();

break;

}

}

}

}

★ ★★★★Form1.designer.cs窗体设计文件完整程序代码★★★★★

namespace _4_02

{

partial class Form1

{

///



/// 必需的设计器变量。

///


private System.ComponentModel.IContainer components = null;

///

/// 清理所有正在使用的资源。

///


/// 如果应释放托管资源,为 true;否则为 false。

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows 窗体设计器生成的代码

///

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

///


private void InitializeComponent()

{

this.textBox1 = new System.Windows.Forms.TextBox();


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.