Light  Rain serena

«November 2025»
1
2345678
9101112131415
16171819202122
23242526272829
30


公告

期待

超级好友 Rachel


我的分类(专题)

首页(262)
知识积累(40)
乐瑟温柔(108)
经验杂谈(20)
良辰吉日(2)
杂七杂八(57)
天景共赏(10)
感触文字(23)


最新日志
sunshine girl
过云雨
summer whisper
边走边唱
岛歌
不必在乎我是谁
如果有来生
Fing Fing 下
大明宫
我没有魅力

最新回复
回复:边界类、控制类、实体类
回复:边界类、控制类、实体类
回复:边界类、控制类、实体类
回复:《极地特快》插曲《When Chr
回复:边界类、控制类、实体类
回复:不必在乎我是谁
回复:边界类、控制类、实体类
回复:如果有来生
回复:Fing Fing 下
回复:我没有魅力

留言板
签写新留言

老大&老师,我想你.....
好文好多阿
886电台 好听
cai
您的子域名已开通
hi
祝福
祝福

你好

统计
blog名称:小雨
日志总数:262
评论数量:1273
留言数量:15
访问次数:4692101
建立时间:2005年1月8日

链接

有事?
音乐,永不厌倦
宁静的心情驿站
我的声音
TIPOblog
tipo bbs
appleVB
网页设计
英语学习2
英语学习3
FLASH
网络书籍
网络电台



我的博客朋友
最有技术的blog
xenium
花差花差
瓜少
span
a lai
琦少
陈少
v
阿当
http://www.ypb.cc/
痞子若鱼
另一个同行
年轻人bcims

 




W3CHINA Blog首页    管理页面    写新日志    退出

[经验杂谈]com+ 松耦合事件
小雨 发表于 2007/1/6 18:10:46

1建立类裤 using System;using System.IO;using System.Reflection;using System.EnterpriseServices;using System.Runtime.InteropServices;using System.Windows.Forms ;[assembly: ApplicationName("EventDemo")][assembly: ApplicationActivation(ActivationOption.Library)][assembly: AssemblyKeyFile("EventDemoSvr.snk")] namespace EventDemo{ public interface ILceMsg {  void EventMethod(string message); }  [EventClass] public class LceClass : ServicedComponent, ILceMsg {  public void EventMethod(string message){} }  public class LceSink : ServicedComponent, ILceMsg {     public void EventMethod(string message)  {   MessageBox.Show(message, "Event sink");  } }} 2建立应用程序 using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using EventDemo;namespace EventTest{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form {  private System.Windows.Forms.Button button1;  /// <summary>  /// 必需的设计器变量。  /// </summary>  private System.ComponentModel.Container components = null;   public Form1()  {   //   // Windows 窗体设计器支持所必需的   //   InitializeComponent();    //   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码   //  }   /// <summary>  /// 清理所有正在使用的资源。  /// </summary>  protected override void Dispose( bool disposing )  {   if( disposing )   {    if (components != null)     {     components.Dispose();    }   }   base.Dispose( disposing );  }   #region Windows 窗体设计器生成的代码  /// <summary>  /// 设计器支持所需的方法 - 不要使用代码编辑器修改  /// 此方法的内容。  /// </summary>  private void InitializeComponent()  {   this.button1 = new System.Windows.Forms.Button();   this.SuspendLayout();   //    // button1   //    this.button1.Location = new System.Drawing.Point(136, 112);   this.button1.Name = "button1";   this.button1.TabIndex = 0;   this.button1.Text = "button1";   this.button1.Click += new System.EventHandler(this.button1_Click);   //    // Form1   //    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);   this.ClientSize = new System.Drawing.Size(292, 273);   this.Controls.Add(this.button1);   this.Name = "Form1";   this.Text = "Form1";   this.ResumeLayout(false);   }  #endregion   /// <summary>  /// 应用程序的主入口点。  /// </summary>  [STAThread]  static void Main()   {   Application.Run(new Form1());  }   private void button1_Click(object sender, System.EventArgs e)  {    ILceMsg evt = (ILceMsg) new LceClass();   evt.EventMethod("Hello events");    } }}3在服务组件   500)this.width=500'>   500)this.width=500'> 500)this.width=500'>

阅读全文(3983) | 回复(1) | 编辑 | 精华

委托和事件
小雨发表评论于2007/1/6 23:54:05

using System; namespace ConsoleApplication3{ /// <summary> /// Class1 的摘要说明。 /// </summary> delegate void myHandle(int i);//定义委托 class person {     public event myHandle newYear; //定义事件 ,新年来了    public void guonian() //过年  {   if(newYear!=null)                newYear(100);//引发事件           else    Console.WriteLine ("事件没有实例化,新年来了也没有钱拿");  } } class Class1 {  /// <summary>  /// 应用程序的主入口点。  /// </summary>  [STAThread]  static void Main(string[] args)  {            myHandle delegate1=new myHandle(println);               person o=new person();//事件源   o.newYear +=delegate1;//实例化事件,给事件添加处理程序   o.guonian();//引发事件   o.newYear -=delegate1;            o.guonian();   Console.ReadLine();  }  public static void println(int i)  {   System.Console.WriteLine ("得了压岁钱  "+i);  } }}

个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除

» 1 »

发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)
站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.063 second(s), page refreshed 144805071 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号