I have a WinForm application, I'm trying to move a pictureBox in a Form using MouseMove Event
, but i can't figure out what's the right calculation should i do on MouseMove, when i first the pictureBox , its location changes in a senseless way then on moving the pictureBox Location moves correctly.
It's a Panel name OuterPanel
which contains the pictureBox picBox
, here the code im using :
private void picBox_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point p = OuterPanel.PointToClient(MousePosition);
picBox.Location = this.PointToClient(p);
}
}
P.S : the goal is moving image after zooming in, like windows photo viewer
Update : ConvertFromChildToForm
method
private Point ConvertFromChildToForm(int x, int y,Control control)
{
Point p = new Point(x, y);
control.Location = p;
return p;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…