如何在WPF中手动向InkCanvas提交事件?

发布于 2024-12-04 09:20:30 字数 127 浏览 2 评论 0原文

我如何能够手动提交事件以供 InkCanvas 接收?

我需要做的是将 InkCanvas 的模式设置为墨迹模式,然后将虚拟事件发送到 InkCanvas,以便我获得就像用户使用真实鼠标一样的绘图行为。

谢谢

How would I be able to submit events manually to be received by InkCanvas ?

What I need to do, is to set the mode of InkCanvas to ink mode, and then, send virtual events to InkCanvas so that I get a drawing behavior as if user used the real mouse.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦在夏天 2024-12-11 09:20:30

以下代码片段显示了在 InkCanvas 中绘制形状的示例:

StylusPointCollection stroke1Points = new StylusPointCollection();
stroke1Points.Add(new StylusPoint(50,10));
stroke1Points.Add(new StylusPoint(90,50));
stroke1Points.Add(new StylusPoint(10,50));
stroke1Points.Add(new StylusPoint(50,10));

Stroke stroke1 = new Stroke(stroke1Points);

canvas.Strokes.Add(stroke1);            

其中 canvas 的类型为 InkCanvas。上面在画布中生成了一个三角形。


“是的,如果答案对您有帮助,您可以接受。”

The following code snippet shows an example of drawing a shape in InkCanvas:

StylusPointCollection stroke1Points = new StylusPointCollection();
stroke1Points.Add(new StylusPoint(50,10));
stroke1Points.Add(new StylusPoint(90,50));
stroke1Points.Add(new StylusPoint(10,50));
stroke1Points.Add(new StylusPoint(50,10));

Stroke stroke1 = new Stroke(stroke1Points);

canvas.Strokes.Add(stroke1);            

Where canvas is of type InkCanvas. The above generates a triangle in the canvas.


"And yes, you may accept the answer if it helps you."

夜司空 2024-12-11 09:20:30

像这样的东西吗?

    private void inkSurface_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        inkSurface.CaptureMouse();

        _inkStroke = new Stroke(
            e.StylusDevice.GetStylusPoints(inkSurface));
        _inkStroke.DrawingAttributes.Width = 5;
        _inkStroke.DrawingAttributes.Height = 5;
        _inkStroke.DrawingAttributes.Color = Colors.Black;

        inkSurface.Strokes.Add(_inkStroke);
        e.Handled = true;
    }

    private void inkSurface_MouseMove(object sender, MouseEventArgs e)
    {
        if (_inkStroke != null)
        {
            _inkStroke.StylusPoints.Add(
                e.StylusDevice.GetStylusPoints(inkSurface));
        }
        e.Handled = true;
    }

    private void inkSurface_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        inkSurface.ReleaseMouseCapture();
        e.Handled = true;
    }

Something like this?

    private void inkSurface_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        inkSurface.CaptureMouse();

        _inkStroke = new Stroke(
            e.StylusDevice.GetStylusPoints(inkSurface));
        _inkStroke.DrawingAttributes.Width = 5;
        _inkStroke.DrawingAttributes.Height = 5;
        _inkStroke.DrawingAttributes.Color = Colors.Black;

        inkSurface.Strokes.Add(_inkStroke);
        e.Handled = true;
    }

    private void inkSurface_MouseMove(object sender, MouseEventArgs e)
    {
        if (_inkStroke != null)
        {
            _inkStroke.StylusPoints.Add(
                e.StylusDevice.GetStylusPoints(inkSurface));
        }
        e.Handled = true;
    }

    private void inkSurface_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        inkSurface.ReleaseMouseCapture();
        e.Handled = true;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文