关于winForm中Eventhandler的问题
Form1.vb
Private Sub init() Dim CR As New Control [color=#FF0000]CR.MouseUpEvent = ????[/color]End SubPrivate Sub afterMouseUp(ByVal sender As Object, ByVal e As EventArgs) Dim Unit As Control = CType(sender, Control) Dim x as Integer = Unit.LocationXEnd Sub
Public MouseUpEvent As EventHandlerPrivate Sub bombControl_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp If e.Button = Windows.Forms.MouseButtons.Left Then MouseUpEvent(sender, e) End IfEnd Sub
直接把Me.MouseUp与afterMouseUp连接,可以同时连多个函数。Private Sub afterMouseUp(ByVal sender As Object, ByVal e As EventArgs) Handles Me.MouseUp Dim Unit As Control = CType(sender, Control) Dim x as Integer = Unit.LocationXEnd Sub或者sub New()......AddHandler Me.Mouseup,AddressOf afterMouseUp.....
[解决办法]
'Remove an existing event-handler
RemoveHandler afterMouseUp, New EventHandler(AddressOf afterMouseUp)
'Add the event handler.
AddHandler afterMouseUp, New EventHandler(AddressOf afterMouseUp)