日期:2014-05-17  浏览次数:20829 次

c# 拖动控件闪烁

最近几天在做画线框的工作,类似于截屏之后修改截屏大小的那种,做完之后发现拖拉线框的时候,线框不停的闪烁,再

?

试了双缓冲技术仍然无果的情况的下,果断觉得是鼠标定位的问题,遂做了如下修改,果断不闪了。\(^o^)/

?

代码修改如下:

?

在pnl_MouseMove(object sender, MouseEventArgs e)事件里

?

e.Location.X 改成?Cursor.Position.X ? ? ? ? ? ?e.Location.Y 改成?Cursor.Position.Y

?

如果你也像我一样一直闪烁,不妨试试这个改动吧,也许会有效果。

?

?

?

注:MousEventArgs.Location 和 Cursor.Position的区别


MouseEventArgs.Positionis the mouse cursor positionrelative to the control during the event,at the time of the event.

MouseEventArgs.Position就是说当控件的事件发生的时候,鼠标在控件上的位置。

Cursor.Positionis thecurrentmouse cursor positionrelative to the desktop.

Cursor.Position就是当前鼠标在桌面上的位置,不需要在控件发生时取到,适合在任何时候获得鼠标的位置

?

?