如何在形状上实现拖动增量

发布于 2024-12-02 18:19:45 字数 1017 浏览 3 评论 0原文

我如何在形状上实现拖动增量,我有以下代码:

void Connector_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        if (e.ClickCount == 1)
        {
            this.Focus();
            this.CaptureMouse();
            this.RaiseEvent(new DragStartedEventArgs(0,0));
            initMousePoint = e.GetPosition(this);
        }
        e.Handled = true;
    }
    void Shape2_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
    {
        currMousePoint = e.GetPosition(this);
        if (this.IsMouseCaptured)
        {
                this.RaiseEvent(new DragDeltaEventArgs(0,0);
        }
    }
    void Shape2_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        this.ReleaseMouseCapture();
    }

现在对于 DragDeltaEvent 参数,我是否需要计算 mousemove 中的拖动并将其传递给事件,这也是引发事件。如果这有效,那么我应该只订阅拖动增量事件并将其用作拇指?请注意,我不想用形状来模板化拇指,提供这个答案对我没有帮助。


请注意关于获取鼠标位置的chagnes,我认为这不起作用,因为它获取相对于元素的位置,而不是包含面板的位置,所以我认为我无法找到拖动距离这样。

How do I go about implementing the drag delta on a Shape, I have the following code:

void Connector_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        if (e.ClickCount == 1)
        {
            this.Focus();
            this.CaptureMouse();
            this.RaiseEvent(new DragStartedEventArgs(0,0));
            initMousePoint = e.GetPosition(this);
        }
        e.Handled = true;
    }
    void Shape2_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
    {
        currMousePoint = e.GetPosition(this);
        if (this.IsMouseCaptured)
        {
                this.RaiseEvent(new DragDeltaEventArgs(0,0);
        }
    }
    void Shape2_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        this.ReleaseMouseCapture();
    }

Now for the DragDeltaEvent args do I need to compute the drag in the mousemove and pass it to the event, also is this the right way to raise the event. If this works, then I should only subscribe to the drag delta event and use it as a thumb? Note, I do not want to template the thumb with the shape, providing this answer won't help me.


note the chagnes, about the getting the position of the mouse, this I don't think works, because it gets the position relative to the element, not the containing panel, so I don't think i will be able to find the drag distance this way.

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

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

发布评论

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

评论(1

怪我闹别瞎闹 2024-12-09 18:19:45

我用以下方法解决了它:

currMousePoint = e.GetPosition(this);
double dragHorizontal = currMousePoint.X - initMousePoint.X;
double dragVertical = currMousePoint.Y - initMousePoint.Y;
//Set the new canvas top and left proeprties here.

I solved it using:

currMousePoint = e.GetPosition(this);
double dragHorizontal = currMousePoint.X - initMousePoint.X;
double dragVertical = currMousePoint.Y - initMousePoint.Y;
//Set the new canvas top and left proeprties here.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文