我有以下错误消息
' AddressOf'操作数必须是方法的名称(没有括号)
尝试以下代码时:
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim xbutton As Control
For Each xbutton In gcFRightMenu.Controls
If xbutton.Name = commandbutton(0) Then
RemoveHandler xbutton.MouseDown, AddressOf xbutton.MouseDown
AddHandler xbutton.MouseDown, AddressOf _MouseDown
End If
Next
End Sub
Private Sub _MouseDown(ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Left Then SendKeys.Send("{ESC}")
End Sub
答案 0 :(得分:1)
您无法删除活动
RemoveHandler xbutton.MouseDown, AddressOf xbutton.MouseDown
AddressOf
期待该方法的名称,但xbutton.MouseDown
是事件的名称。
如果您想确保eventhandler _MouseDown
仅向控件添加了一个,则在添加
For Each xbutton In gcFRightMenu.Controls
If xbutton.Name = commandbutton(0) Then
RemoveHandler xbutton.MouseDown, AddressOf _MouseDown
AddHandler xbutton.MouseDown, AddressOf _MouseDown
End If
Next