Drawing with Touch in WinRT

1

I'm using the following example. http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.input.pointereventhandler?cs-save-lang=1&cs-lang=vb#code-snippet-1

I've tried modifying it a few different ways but am not able to make touch work to draw with on the screen.

The program fails on this function

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

I get the following error Message=TabletPC inking error code. Initialization failure (Exception from HRESULT: 0x80040223) on the _inkManager.ProcessPointerDown(pt) line.

c#
.net
vb.net
touch
windows-runtime
asked on Stack Overflow Nov 12, 2012 by sonicbabbler • edited Nov 13, 2012 by sonicbabbler

1 Answer

2

I found a solution at: http://www.c-sharpcorner.com/uploadfile/269510/metro-style-paint-application/ In this example he just started drawing. So I've modified the above procedure and removed the inkManager options and now I am able to draw with my finger.

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
answered on Stack Overflow Nov 13, 2012 by sonicbabbler

User contributions licensed under CC BY-SA 3.0