wpf:捕获鼠标不起作用 [英] wpf: capturing mouse does not work

查看:318
本文介绍了wpf:捕获鼠标不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一种Outlook日历应用程序,需要从鼠标中调整约会的大小. 我第一次用拇指尝试无法正常工作,所以我尝试了另一种方法.

I am developing an kind of outlook calendar application where I need to make the appointment resizable from mouse. My first try with a thumb did not work properly so I tried another way.

我所做的是:

1)在指定面板的底部,我添加了一个矩形以找出调整大小区域(拇指).约会面板放在网格面板上. 2)我在矩形上拦截事件并将事件发送到此代码:

1) on the botton of the appointmennt panel I added a rectangle to figure out the resize zone (the thumb). The appointment panel is put on a grid panel. 2) I intercept down event on the rectangle and send event to this code:

private Point startPoint;
private void OnResizeElementMouseDown(object sender, MouseButtonEventArgs e)
{
    e.Handled = true;
    this.MouseMove += new MouseEventHandler(ResizeEndElement_MouseMove);
    this.MouseLeftButtonUp += new MouseButtonEventHandler(OnResizeElementMouseUp);
    // some code to perform new height computation
    Mouse.Capture(this);
}

这是拥有拇指的约会面板.

where this is the appointment panel that own the thumb.

降低高度效果很好. 但是增加难度更大.如果我非常缓慢地移动鼠标,就可以了,如果我加快一点速度,它往往会忽略约会面板,然后所有的MouseMove事件都会丢失.

Decreasing height works well. But increasing is more difficult. If I move the mouse very very slowly it's OK, if I speed it up a little bit it tends to leave out the appointment panel and then all MouseMove event are lost.

我以为提出了Mouse.Capture()解决此类问题的建议,但实际上并非如此.

I thought Mouse.Capture() was propose to solve this kind of problem, but in fact not.

有人知道我的代码出了什么问题吗?

Does anybody know what is wrong in my code?

推荐答案

您应该使用拇指,但是要使用鼠标捕获,请覆盖protected override void OnLostMouseCapture(MouseEventArgs e)方法,然后您将知道是否丢失了捕获.

you should use a thumb, but to play with mouse capture, override the protected override void OnLostMouseCapture(MouseEventArgs e) method, then you will know if you have lost the capture.

这篇关于wpf:捕获鼠标不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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