Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 设置鼠标位置,在画布上引发单击事件_Wpf_Vb.net_Canvas - Fatal编程技术网

Wpf 设置鼠标位置,在画布上引发单击事件

Wpf 设置鼠标位置,在画布上引发单击事件,wpf,vb.net,canvas,Wpf,Vb.net,Canvas,我现在使用的这个功能有点棘手,所以我需要一些帮助来找到解决方案。 问题是,我必须从代码中在画布上引发MouseDown事件,并传递鼠标在画布中的位置以及其他参数。 是VB.Net中的一个项目,我知道我不需要'Call'关键字,但我保留它只是为了澄清代码:) 这是我的代码,但仍然不知道如何传递此调用的鼠标位置 Call picture_MouseDown(picture, New MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButto

我现在使用的这个功能有点棘手,所以我需要一些帮助来找到解决方案。 问题是,我必须从代码中在画布上引发MouseDown事件,并传递鼠标在画布中的位置以及其他参数。 是VB.Net中的一个项目,我知道我不需要'Call'关键字,但我保留它只是为了澄清代码:) 这是我的代码,但仍然不知道如何传递此调用的鼠标位置

    Call picture_MouseDown(picture, New MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left))
假设我有这两个变量的X和Y位置:

    CInt(XC), CInt(YC)

提前感谢您,我非常感谢您的帮助:)

您不应该直接调用事件处理程序。相反,请将单击图片框时出现的功能分离到一个单独的方法中,并从两个位置调用该方法:

Class MainWindow 
    Private Sub Canvas1_MouseDown(sender As System.Object, e As System.Windows.Input.MouseButtonEventArgs) Handles Canvas1.MouseDown
        DoSomethingWithCanvas(sender, e.GetPosition(sender), e.ChangedButton)
    End Sub

    Private Sub SomeOtherSub()
        Dim XC As Double = 100.0
        Dim YC As Double = 100.0

        'Do the code that would normally happen if the picturebox was actually clicked.
        DoSomethingWithCanvas(Canvas1, New Point(CInt(XC), CInt(YC)), MouseButton.Left)
    End Sub

    Private Sub DoSomethingWithCanvas(picBox As Canvas, loc As Point, button As MouseButton)
        'Some Code here that manipulates the Canvas
        If button = MouseButton.Left Then
            'Do something for left button click
        End If
    End Sub
End Class

这叫做命中测试,它的工作原理是这样的:嗯,谢谢你,刺猬,但仍然没有找到方法来做。我需要将X和Y的位置传递给事件处理程序。您需要发布更多代码