1

我正在使用以下示例。http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.input.pointereventhandler?cs-save-lang=1&cs-lang=vb#code-snippet-1

我尝试用几种不同的方式对其进行修改,但无法使触摸工作在屏幕上进行绘制。

程序在此功能上失败

Public Function InkCanvas_PointerPressed(sender As Object, e As PointerRoutedEventArgs)

    'Get information about the pointer location
    Dim pt As PointerPoint = e.GetCurrentPoint(panelcanvas)
    _previousContactPt = pt.Position

    'Accept input only from a pen or mouse with a left button pressed
    Dim pointerDevType As PointerDeviceType = e.Pointer.PointerDeviceType

    If ((pointerDevType = PointerDeviceType.Pen Or pointerDevType = PointerDeviceType.Mouse) And pt.Properties.IsLeftButtonPressed) Then
        'Pass the point information to the inkmanager

        _inkManager.ProcessPointerDown(pt)
        _penID = pt.PointerId
        e.Handled = True

    ElseIf (pointerDevType = PointerDeviceType.Touch) Then

        _touchID = pt.PointerId
        _inkManager.ProcessPointerDown(pt) '<-- error happens here



        e.Handled = True


    End If

    Return Nothing
End Function

我收到以下错误消息 = TabletPC 墨迹错误代码。_inkManager.ProcessPointerDown(pt) 行上的初始化失败(HRESULT 异常:0x80040223)。

4

1 回答 1

2

我在以下位置找到了一个解决方案:http ://www.c-sharpcorner.com/uploadfile/269510/metro-style-paint-application/ 在这个例子中,他刚开始画画。所以我修改了上述程序并删除了 inkManager 选项,现在我可以用手指绘图了。

Public Function InkCanvas_PointerPressed(sender As Object, e As PointerRoutedEventArgs)

    'Get information about the pointer location
    Dim pt As PointerPoint = e.GetCurrentPoint(panelcanvas)
    _previousContactPt = pt.Position

    'Accept input only from a pen or mouse with a left button pressed
    Dim pointerDevType As PointerDeviceType = e.Pointer.PointerDeviceType

    If ((pointerDevType = PointerDeviceType.Pen Or pointerDevType = PointerDeviceType.Mouse) And pt.Properties.IsLeftButtonPressed) Then
        'Pass the point information to the inkmanager

        _inkManager.ProcessPointerDown(pt)
        _penID = pt.PointerId
        e.Handled = True

    ElseIf (pointerDevType = PointerDeviceType.Touch) Then
        '_inkManager.ProcessPointerDown(pt)


        Dim NewLine As Line = New Line
        NewLine.X1 = e.GetCurrentPoint(panelcanvas).Position.X
        NewLine.Y1 = e.GetCurrentPoint(panelcanvas).Position.Y
        NewLine.X2 = NewLine.X1 + 1
        NewLine.Y2 = NewLine.Y1 + 1
        NewLine.StrokeThickness = 4.0
        NewLine.Stroke = New SolidColorBrush(Colors.Red)
        panelcanvas.Children.Add(NewLine)
        _touchID = pt.PointerId
        e.Handled = True

    End If

    Return Nothing
End Function
于 2012-11-13T14:58:05.253 回答