调用鼠标dobleclick在用户控件(winforms)的windowsformhost(wpf)上

时间:2019-05-03 17:28:50

标签: wpf vb.net user-controls windowsformshost

我正在创建一个wpf应用程序,但是我似乎无法处理用户控件的事件 在mainwindow.axml中,我创建了一个Windowsformhost,并在运行时完美加载了内容(加载数据集的数据等),但是我该如何处理鼠标或键盘按下的事件呢?

在用户控件中:

Public Event DOBLECLICK()
Public Sub sp1_CellDoubleClick(sender As Object, e As 
    FarPoint.Win.Spread.CellClickEventArgs) Handles sp1.CellDoubleClick
    RaiseEvent DOBLECLICK()
End Sub

在主窗口中: 我尝试加载事件,但似乎没有响应。

Private Sub WinFormsHost_MouseLeftButtonUp(sender As Object, e As 
    MouseButtonEventArgs) Handles WinFormsHost.MouseLeftButtonUp

    AddHandler host.sp1.CellDoubleClick, AddressOf host.sp1_CellDoubleClick

End Sub


Private Sub Control_MouseDoubleClick_1(sender As Object, e As MouseEventArgs)
    AddHandler host.sp1.CellDoubleClick, AddressOf host.sp1_CellDoubleClick
End Sub

1 个答案:

答案 0 :(得分:0)

(λ (x) (polyX x)) 函数中,添加以下内容:

MainWindow_Loaded

然后在您的类中创建一个新函数(双击单元格时会调用该函数。在此之后不要使用AddHandler host.sp1.CellDoubleClick, AddressOf host.sp1_CellDoubleClick ,因为您已经在Handles中添加了该处理函数):

MainWindow_Loaded

不需要功能Public Sub sp1_CellDoubleClick(sender As Object, e As FarPoint.Win.Spread.CellClickEventArgs) RaiseEvent DOBLECLICK() End Sub WinFormsHost_MouseLeftButtonUp。您可以删除它们。