首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

关于winForm中Eventhandler的有关问题

2012-08-27 
关于winForm中Eventhandler的问题Form1.vbVB.NET codePrivate Sub init()Dim CR As New Control[color#FF

关于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)

热点排行