VB.NET withevent事件处理

Module Module1
    Private WithEvents aemp As employeeevent
    Sub Main()
        Dim chen As New employeeevent("chenlili", 10000)
        aemp = chen
        Console.WriteLine(chen.Name & " previous salary is : " & chen.Salary)
        aemp.AddSalary(0.3D)
        Console.WriteLine(chen.Name & " current salary is : " & chen.Salary)
        Console.ReadLine()
    End Sub

    Public Sub aemp_AddSalaryEvent(ByVal sender As ConsoleApplication1.employeeevent, ByVal e As System.EventArgs) Handles aemp.AddSalaryEvent
        MsgBox(sender.Name & " want to invalid add salary !")
    End Sub
End Module

Public Class employeeevent
    Private m_name As String
    Private m_salary As Decimal
    Private Const limitvalue As Decimal = 0.07
    Public Event AddSalaryEvent(ByVal sender As employeeevent, ByVal e As EventArgs) 'add declare event code here
    Public Sub New(ByVal sname As String, ByVal salary As Decimal)
        m_name = sname
        m_salary = salary

    End Sub
    Public ReadOnly Property Name() As String
        Get
            Return m_name

        End Get
    End Property
    Public ReadOnly Property Salary() As Decimal
        Get
            Return m_salary

        End Get
    End Property
    Public Overridable Overloads Sub AddSalary(ByVal per As Decimal)
        If per > limitvalue Then
            RaiseEvent AddSalaryEvent(Me, New System.EventArgs())'raise event to come across
        Else
            m_salary = m_salary * (1 + per)
        End If
    End Sub


End Class

 

posted @ 2013-07-25 12:42  MMLoveMeMM  阅读(803)  评论(0)    收藏  举报