工作流设计器线 onclick 太细 [英] Workflow designer line onclick too thin

查看:25
本文介绍了工作流设计器线 onclick 太细的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个工作流设计器,用 wpf 和 vb.net 在画布上创建工作流.我使在具有良好功能的对象之间绘制线条(关系)成为可能.现在我想实现一种删除关系的方法.我在形状上添加了一个 onclick 处理程序,但线条非常细且难以点击.我听说用较粗的笔画粗细画 2 条线 1,但这是不可能的,因为画线方法对 cpu 很重.

I'm making a workflowdesigner to create workflows on a canvas with wpf and vb.net. I have made it possible to draw lines(relations) between objects with a nice function. Now I want to implement a way to delete a relation. I add a onclick handler on the shape but the line is very thin and hard to click. I've heard to draw 2 lines 1 with a thicker stroke thickness, but this isn't possible since the drawline method is heavy on the cpu.

感谢您的帮助

大卫

推荐答案

您可以将鼠标按下事件处理程序添加到 Canvas,而不是 Shape 对象,然后执行 视觉层中的命中测试(虽然API有点奇怪)带有命中测试几何体,例如椭圆.Canvas 需要将其 Background 设置为(例如,设置为 Transparent)以接收鼠标事件.

You could add a mouse down event handler to the Canvas, instead of the Shape objects, and then do Hit Testing in the Visual Layer (although the API is a bit strange) with a hit test geometry, for example an ellipse. The Canvas needs to have its Background set (e.g. to Transparent) to receive mouse events.

抱歉,这是 C#,但我不会说 VB:

Sorry that this is C#, but i don't speak VB:

private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    Canvas canvas = sender as Canvas;
    EllipseGeometry hitTestGeometry =
        new EllipseGeometry(e.GetPosition(canvas), 10d, 10d);
    Shape hitShape = null;

    HitTestResultCallback hitTestCallback =
        result =>
        {
            hitShape = result.VisualHit as Shape;
            return hitShape != null ? HitTestResultBehavior.Stop : HitTestResultBehavior.Continue;
        };

    VisualTreeHelper.HitTest(canvas, null, hitTestCallback, new GeometryHitTestParameters(hitTestGeometry));

    if (hitShape != null)
    {
        System.Diagnostics.Trace.TraceInformation("hit shape: {0}", hitShape);
    }
}

这是等效的 VB 代码.VB 不支持多行 lambda 表达式,因此必须显式声明命中测试回调

Here is the equivalent VB code. VB does not support multiline lambda expressions so the hit test callback has to be declared explicitly

Private Function htCallback(ByVal result As HitTestResult) _
 As HitTestResultBehavior
    Dim hitShape As Shape = Nothing
    hitShape = TryCast(result.VisualHit, Shape)
    If hitShape IsNot Nothing Then
        'do something 
    End If
    Return If(hitShape IsNot Nothing, HitTestResultBehavior.[Stop], _
      HitTestResultBehavior.[Continue])
End Function


Private Sub Canvas_MouseLeftButtonDown(ByVal sender As Object, _
  ByVal e As MouseButtonEventArgs) Handles Canvas1.MouseRightButtonDown
    Dim canvas As Canvas = TryCast(sender, Canvas)
    Dim hitTestGeometry As New EllipseGeometry(e.GetPosition(canvas), 10.0, 10.0)
    Dim hitTestCallback As HitTestResultCallback = _
      New HitTestResultCallback(AddressOf htCallback)
    VisualTreeHelper.HitTest(canvas, Nothing, hitTestCallback, _
      New GeometryHitTestParameters(hitTestGeometry))
End Sub

这篇关于工作流设计器线 onclick 太细的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆