关于winForm中Eventhandler的问题
Form1.vb
- VB.NET code
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
Control.vb
- VB.NET code
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
我想在左键松开时,执行Form1.vb里的afterMouseUp方法,该怎么写啊,找了各种办法都不行,小弟新手!多谢!
[解决办法]
AddHandler Form1_MouseUp, AddressOf 方法名
[解决办法]
- VB.NET code
直接把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)