我试图将相同的处理程序添加到我表单中的所有控件中。这是我的代码:
Sub CreateDelegates()
For Each Ctl In Me.Controls
AddHandler Ctl.MouseDown, AddressOf MainPictureBox_MouseDown
Next
End Sub
问题是MouseDown
未被识别为Object
的事件。知道如何解决这个问题吗?
谢谢
答案 0 :(得分:2)
以这种方式尝试:
For Each Ctl As Control In Me.Controls
AddHandler Ctl.MouseDown, AddressOf MainPictureBox_MouseDown
Next
如果这些都是PictureBox控件,那么过滤它们可能会更好:
For Each Ctl As PictureBox In Me.Controls.OfType(Of PictureBox)()
AddHandler Ctl.MouseDown, AddressOf MainPictureBox_MouseDown
Next