2012-11-12 37 views
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在WinRT中使用觸摸繪圖

我試過修改它幾種不同的方法,但我不能使觸摸工作在屏幕上繪製。

該程序失敗關於此函數

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)。

回答

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