简体   繁体   English

WPF c# 鼠标事件不工作/或使用 wacom 图形设备非常慢

[英]WPF c# mouseevents not working/or very slow with wacom graphic device

I want to draw something with my wacom graphic tablet on a canvas. I've written some code and I can draw very well with the mouse.我想在 canvas 上用我的 wacom 绘图板画一些东西。我写了一些代码,我可以用鼠标画得很好。 However, with the wacom graphic tablet, it only works sometimes and slower.但是,使用 wacom 图形输入板时,它只能有时工作,而且速度较慢。 The problem is the OnMouseDown event which is only detected after a considerable time delay.问题在于 OnMouseDown 事件,它仅在相当长的时间延迟后才被检测到。

Here is my code:这是我的代码:

public partial class MainWindow : Window
{
    private Polyline myPolyline;
    private Boolean isMouseDown;
    public MainWindow()
    {
        InitializeComponent();
    }

    private void OnMouseDown(object sender, MouseButtonEventArgs e)
    {
    
        isMouseDown = true;
        Point p = e.GetPosition(mycanvas);
        myPolyline = new Polyline();
        myPolyline.Stroke = System.Windows.Media.Brushes.SlateGray;
        myPolyline.StrokeThickness = 2;
        myPolyline.FillRule = FillRule.EvenOdd;
        PointCollection myPointCollection = new PointCollection();
        myPointCollection.Add(p);
        myPolyline.Points = myPointCollection;
        mycanvas.Children.Add(myPolyline);
    
    }

    private void OnMouseUp(object sender, MouseButtonEventArgs e)
    {
    
        isMouseDown = false;
     
    }

    private void OnMouseMove(object sender, MouseEventArgs e)
    {
    
        Point p = e.GetPosition(mycanvas);
        
        if (!isMouseDown)
        {
            return;
        }
       

        myPolyline.Points.Add(p);
      
    }

}

And here is the xaml这是 xaml

<Window x:Class="WpfApp1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApp1"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
<StackPanel>
   
    <Canvas Background="Azure" x:Name="mycanvas" Width="800" Height="450" MouseDown="OnMouseDown" MouseUp="OnMouseUp" MouseMove="OnMouseMove" ></Canvas>

   
</StackPanel>

Your code is using MouseButtonEventArgs and MouseEventArgs instead of the Wacom-specific event argument types.您的代码使用 MouseButtonEventArgs 和 MouseEventArgs 而不是 Wacom 特定的事件参数类型。

You can try to replace your existing mouse event handlers with the API provided by Wacom.您可以尝试用 Wacom 提供的 API 替换您现有的鼠标事件处理程序。

Wacom provides dedicated APIs on several platforms that allow you to directly access Wacom tablets. Wacom 在多个平台上提供专用 API,让您可以直接访问 Wacom 数位板。

For example, on Windows, you can use the Ink API provided by Wacom to access Wacom graphics tablets.比如Windows,可以使用Wacom提供的Ink API接入Wacom数位板。

This API provides all events and data related to Wacom tablets.此 API 提供与 Wacom 数位板相关的所有事件和数据。 Using the Ink API can help you respond to Wacom tablet events faster and use more precise data to control the brush.使用 Ink API 可以帮助您更快地响应 Wacom 数位板事件并使用更精确的数据来控制画笔。

Maybe you can refer to this link .也许你可以参考这个链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM