关于c#中鼠标事件很诡异的现象
我自己用vs2005写了个工程,我用那些鼠标的事件,类似于:
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
这种函数,怎么无论如何函数里面的代码都不被执行,好像压根没有进这个函数。
我网上下载的例子,里面有这个函数的,都能执行。
于是我把人家的代码粘贴放在我的工程里面,又不能执行了,真是很诡异的现象
哪位大哥知道原因呢?
下面是抄的别人的代码:
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
// Check if dragging of the form has occurred
if (e.Button == MouseButtons.Left)
{
// If this is the first mouse move event for left click dragging of the form,
// store the current point clicked so that we can use it to calculate the form's
// new location in subsequent mouse move events due to left click dragging of the form
if (isFirst == true)
{
// Store previous left click position
prevLeftClick = new Point(e.X, e.Y);
// Subsequent mouse move events will not be treated as first time, until the
// left mouse click is released or other mouse click occur
isFirst = false;
}
// On subsequent mouse move events with left mouse click down. (During dragging of form)
else
{
// This flag here is to allow alternate processing for dragging the form because it
// causes serious flicking when u allow every such events to change the form's location.
// You can try commenting this out to see what i mean
if (toBlock == false)
this.Location = new Point(this.Location.X + e.X - prevLeftClick.X, this.Location.Y + e.Y - prevLeftClick.Y);
// Store new previous left click position
prevLeftClick = new Point(e.X, e.Y);
// Allow or deny next mouse move dragging event
toBlock = !toBlock;
}
}
// This is a new mouse move event so reset flag
else
isFirst = true;
}