当鼠标悬停在其他对象上时,对象停止跟踪鼠标位置C#

时间:2014-11-25 23:18:01

标签: c# button mouseevent

我有一个程序,它使用鼠标的.X位置(相对于表单边界)来更改按钮Object的.Left值。

问题在于我将此按钮放在其他对象的顶部,如图片框,按钮,TrackBar等。当我将这些其他元素移动时,该按钮会停止跟踪鼠标的.X位置。

如果鼠标在表单上执行其他操作,如何使按钮跟踪鼠标移动? (我也需要同时与其他元素进行交互)。

我的代码:

/* i create the mousemove tracking event */    
this.MouseMove += new MouseEventHandler(btnBat1_MouseMove);

/* and use it by making a new method */
public void btnBat1_MouseMove(Object sender, MouseEventArgs e)
{
  // I use the variable mouseXCo to change the button1.Left value.
  mouseXCo = e.X;
}

先谢谢你们: - )

0 个答案:

没有答案