c# 事件委托小例子
来源:互联网 发布:电脑软件学校 编辑:程序博客网 时间:2024/04/30 20:16
希望对初学者有点帮助
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace QQAutoMan
...{
public partial class frmMain : Form
...{
//声明一个委托
public delegate void ReceivedEventHandler(object sender, System.EventArgs e);
//声明一个事件
public event ReceivedEventHandler Received;
// 用以触发Received事件
protected virtual void OnReceived(EventArgs e)
...{
if (this.Received != null)
this.Received(this, e);
}
private string _data = "";
// Data属性
public string data
...{
get ...{ return this._data; }
set
...{
this._data = value;
// 数据改变时触发Received事件
this.OnReceived(new EventArgs());
}
}
public frmMain()
...{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
...{
this.Received += new ReceivedEventHandler(showdata);
}
private void showdata(object sender, System.EventArgs e)
...{
MessageBox.Show("收到你发来的数据:" + this.data);
}
private void button1_Click(object sender, EventArgs e)
...{
this.data = "abcd";
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace QQAutoMan
...{
public partial class frmMain : Form
...{
//声明一个委托
public delegate void ReceivedEventHandler(object sender, System.EventArgs e);
//声明一个事件
public event ReceivedEventHandler Received;
// 用以触发Received事件
protected virtual void OnReceived(EventArgs e)
...{
if (this.Received != null)
this.Received(this, e);
}
private string _data = "";
// Data属性
public string data
...{
get ...{ return this._data; }
set
...{
this._data = value;
// 数据改变时触发Received事件
this.OnReceived(new EventArgs());
}
}
public frmMain()
...{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
...{
this.Received += new ReceivedEventHandler(showdata);
}
private void showdata(object sender, System.EventArgs e)
...{
MessageBox.Show("收到你发来的数据:" + this.data);
}
private void button1_Click(object sender, EventArgs e)
...{
this.data = "abcd";
}
}
}
- c# 事件委托小例子
- 事件委托小例子
- C#中的委托和事件(小例子)
- C#委托经典小例子
- 一个小例子理解事件委托
- C#关于委托与事件的例子
- C# 委托与事件的例子
- C#事件-经典小例子
- c#事件处理小例子
- C# 委托 事件 学习 以及 小DEMO
- 事件委托的例子
- 事件委托例子1
- 理解C#中事件和委托的例子
- 理解C#中事件和委托的例子
- C# 中的委托和事件 (很好的说明例子)
- 帮助理解c#中委托+事件的一个例子
- C#中委托和事件的对比例子
- 个人理解c#的委托和事件,附带例子
- 谢谢 共享资源的朋友
- Js 获取IP方法
- 架构师书单 2nd Edition
- 项目管理--系统后期维护的一点心得
- VS2005起始页中不显示最近打开的项目
- c# 事件委托小例子
- 不能访问 windows installer 服务
- I Find Some!
- 谁是穷人
- 网络安全工具开发函数库Libnet
- delphi 带参数执行外部程序
- VS2003/VS2005 知识点
- 解决无法单击弹出网页
- 线程中的timer