我想用我的鼠標,所以我就到這裏來移動一個PictureBox:如何用鼠標移動圖片? C#形式
private void pictureB_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(image, recLoc);
}
private void pictureB_MouseDown(object sender, MouseEventArgs e)
{
WorkAble = true;
choosingPoint.X = e.X;
choosingPoint.Y = e.Y;
lastPoint.X = e.X;
lastPoint.Y = e.Y;
}
private void pictureB_MouseMove(object sender, MouseEventArgs e)
{
if (WorkAble)
{
recLoc.X = e.X - choosingPoint.X;// + lastPoint.X;
recLoc.Y = e.Y - choosingPoint.Y;// + lastPoint.Y;
pictureB.Refresh();
}
}
private void pictureB_MouseUp(object sender, MouseEventArgs e)
{
WorkAble = false;
lastPoint.X = e.X;
lastPoint.Y = e.Y;
}
// recLoc = pictureBox Location.
好,它的偉大工程。但是不是完全.. 一旦執行KeyUp事件我的意思是,然後再次單擊該圖像將返回到pictureBox的0,0點。 爲了克服這一點,我添加了lastPoint點,並在鼠標移動中添加它的值。 因此,一方面它確實在最後一個下降的點上繪製圖像,但鼠標將位於圖像的0,0點,而不是我點擊的位置 - 圖像上。就像我點擊圖像的中心,鼠標將在0,0點..
任何建議如何解決它?
WOW謝謝!無法相信我沒有看到.. –