代码:
Dim x, y as [Delegate]
x = Sub() MeMouseMove(points)
y = Sub() MeMouseDown(points)
AddHandler MainGrid.MouseMove, x
AddHandler MainGrid.MouseLeftButtonDown, y
代码背景:
问题:
我收到错误:
未处理的类型' System.InvalidCastException'发生
附加信息:无法转换类型' VB $ AnonymousDelegate_0'输入' System.Windows.Input.MouseEventHandler'。
我认为问题在于声明x和y变量
任何帮助都将非常感谢,并感谢时间,红色
答案 0 :(得分:1)
MouseEventHandler有两个参数Object sender和RoutedEventArgs e,所以你应该试试
x = Sub(s, e) MeMouseMove(points)
y = Sub(s, e) MeMouseDown(points)
AddHandler MainGrid.MouseMove, AddressOf x
AddHandler MainGrid.MouseLeftButtonDown, AddressOf y
答案 1 :(得分:0)
找到解决方案
Dim x As New MouseEventHandler(Sub() MeMouseMove(points))
Dim y As New MouseButtonEventHandler(Sub() MeMouseDown(points))
将变量'x'和'y'更改为适当的变量类型(不是[Delegate])