读书人

帮小弟我调个程序

发布时间: 2012-02-12 17:16:34 作者: rapoo

帮我调个程序
bool bPictureBoxDragging = false;
Point oPointClicked;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
PictureBox p = (PictureBox)sender;
pictureBox1.Cursor = Cursors.Hand;
bPictureBoxDragging = true;
oPointClicked = e.Location;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (bPictureBoxDragging)
{
DoubleBuffered = true;
Point oMoveToPoint;
oMoveToPoint = pictureBox1.PointToScreen(e.Location);
oMoveToPoint.Offset(oPointClicked.X * -1, oPointClicked.Y * -1);
pictureBox1.Location = oMoveToPoint;
}
}

private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
bPictureBoxDragging = false;
pictureBox1.Cursor = Cursors.Arrow;
}

大家帮我看看,为什么鼠标按下移动的时候图片会跳一下??怎么解决?


[解决办法]
我用的vs2003,怎么MouseEventArgs e,没有Location这个属性,难道楼主用的2005?
pictureBox1.Location = oMoveToPoint//有这句话,图片的位置当然会随鼠标变化了
[解决办法]
你这样来做试试看:
Point lastPoint = Point.Empty;
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
PictureBox box = sender as PictureBox;
if (box.Capture)
{
Point loc = box.Location;
loc.Offset(e.Location.X - lastPoint.X, e.Location.Y - lastPoint.Y);
box.Location = loc;
}
}

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
lastPoint = e.Location;
}
------解决方案--------------------


oMoveToPoint.Offset(oPointClicked.X * -1, oPointClicked.Y * -1);
这句话有问题,改成楼上的方法,应该对了

读书人网 >C#

热点推荐