小刀人
-No business too small, no problem too big.
<2010年3月>
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
公告
  • Learn,Think,and Imagine...

    正在看的书:

    点击发送消息给我

留言簿(6)

随笔分类

随笔档案

文章档案

相册

CSDN

VC知识库

开发站点

技术blog

搜索

最新评论

  • 1. purchase xanax
  • Some editors are failed writers, but so are most writers.
  • --purchase xanax
  • 2. neomwvbl
  • --neomwvbl
  • 3. order xanax
  • Think of yourself as an incandescent power, illuminated and perhaps forever talked to by God and his messengers.
  • --order xanax
  • 4. cialis for
  • It is your work in life that is the ultimate seduction.
  • --cialis for
  • 5. ffysegxg
  • --ffysegxg
  • 6. ammonation
  • God is a comedian playing to an audience too afraid to laugh.
  • --ammonation
  • 7. dyed
  • That would be a good thing for them to cut on my tombstone: Wherever she went, including here, it was against her better judgment.
  • --dyed
  • 8. ebullioscopic
  • We are made to persist. That's how we find out who we are.
  • --ebullioscopic
  • 9. keppra
  • They are ill discoverers that think there is no land, when they can see nothing but sea.
  • --keppra
  • 10. ampicillin
  • Any transition serious enough to alter your definition of self will require not just small adjustments in your way of living and thinking but a full-on metamorphosis.
  • --ampicillin
  • 11. reglan
  • The most erroneous stories are those we think we know best - and therefore never scrutinize or question.
  • --reglan
  • 12. oryxbxoc
  • --oryxbxoc
  • 13. linnaeite
  • In America, they want you to accomplish these great feats, to pull off these David Copperfield-type stunts. You want me to be great, but you don't ever want me to say I'm great?
  • --linnaeite
  • 14. humungous
  • --humungous
  • 15. doxycycline hyclate
  • There are sadistic scientists who hurry to hunt down errors instead of establishing the truth.
  • --doxycycline hyclate
  • 16. cephalexin 500mg hypermedia argyrophil
  • It is not enough to aim; you must hit.
  • --cephalexin 500mg hypermedia argyrophil
  • 17. female viagra
  • Good judgment comes from experience, and experience comes from bad judgment.
  • --female viagra
  • 18. sjkovbbg
  • --sjkovbbg
  • 19. datapath
  • We don't know a millionth of one percent about anything.
  • --datapath
  • 20. verticilliose
  • All truth passes through three stages. First, it is ridiculed. Second, it is violently opposed. Third, it is accepted as being self-evident.
  • --verticilliose

阅读排行榜

评论排行榜

 
VC知识库BLOG   首页  新随笔  联系  聚合  登录 
  随笔-23 文章-0 评论-184 Trackbacks-0
Bill Horst (view profile)
March 30, 2005
翻译:小刀人

Environment:  VB .NET 2005

本文提供了自定义事件的介绍,一个VB .NET 2005的新的语言特性。自定义事件允许在事件的AddHandler, RemoveHandler, 和RaiseEvent 被调用时由用户指定要做什么。
Visual Basic 2005 有一些在以前的VB.NET版本中没有的新的特性。其中一个就是能创建自定义事件以使得程序员可以在AddHandler, RemoveHandler, 和RaiseEvent 被调用时指定要做什么。
下面是一个使用自定义事件的VB代码以记录数据处理的变化。当然,这只是一个如何使用自定义事件的例子,该方法基本上可以被用于任何目的。

Delegate Sub MyDelegate(ByVal message As String)

Class MyClass1
   Custom 
Event MyEvent As MyDelegate

      
' 这段代码将AddHandler MyEvent, D1被调用时运行
      AddHandler(ByVal value As MyDelegate)
         Console.
WriteLine("Adding Handler for MyEvent")
         MyEventHandler 
= value
      
End AddHandler

      
' 这段代码将RemoveHandler MyEvent, D1被调用时运行
      RemoveHandler(ByVal value As MyDelegate)
         Console.
WriteLine("Removing Handler for MyEvent")
         MyEventHandler 
= Nothing
      
End RemoveHandler

      
' 这段代码将RaiseEvent MyEvent(string)被调用时运行
      RaiseEvent(ByVal message As String)
         
If Not MyEventHandler Is Nothing Then
            MyEventHandler.Invoke(message)
         
Else
            Console.
WriteLine("No Handler for Raised MyEvent")
         
End If
      
End RaiseEvent
   
End Event

   
Public MyEventHandler As MyDelegate

   
Public Sub Raise_Event()
      
RaiseEvent MyEvent("MyEvent Was Raised")
   
End Sub

End Class


Module DelegateModule
   
Dim Var1 As MyClass1
   
Dim D1 As MyDelegate

   
Sub Main()
      Var1 
= New MyClass1
      D1 
= New MyDelegate(AddressOf MyHandler)
      
AddHandler Var1.MyEvent, D1
      Var1.Raise_Event()
      
RemoveHandler Var1.MyEvent, D1
   
End Sub


   
Sub MyHandler(ByVal message As String)
      Console.
WriteLine("Event Handled: " & message)
   
End Sub

End Module



原文链接:http://www.codeguru.com/vb/gen/vb_general/idelanguage/article.php/c9481

posted on 2005-05-22 22:47 小刀人 阅读(4837) 评论(0)  编辑 收藏
Comments
标题  
姓名  
主页
验证码 *
内容   
  登录  使用高级评论  Top
[使用Ctrl+Enter键可以直接提交]