Chinaunix首页 | 论坛 | 博客
  • 博客访问: 156454
  • 博文数量: 23
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 450
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-11 14:36
文章分类

全部博文(23)

文章存档

2011年(1)

2009年(3)

2008年(19)

我的朋友

分类: WINDOWS

2008-09-16 19:11:54

基本思路:
1,首先在要定义事件的类中声明事件,然后使用RaiseEvent 激发该事件.
Public Class Person

  Private name As String

   Public Event walked(ByVal distance As Integer)
   
  Public Sub onwalk(ByVal distance As Integer)
    RaiseEvent walked(distance)

  End Sub
End Class
2. 使用WithEvents 声明该类的对象.
  Friend WithEvents myperson As Person
3,编写事件处理代码.
  Private Sub myperson_walked(ByVal distance As Integer) -
   Handles myperson.walked
   TextBox1.Text = "walked" & distance
   End Sub

4,调用事件.
  Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)  Handles Button1.Click
  myperson.onwalk(20)

  End Sub
阅读(3636) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~