鼠标拖动移动图片位置"/>
winform 鼠标拖动移动图片位置
- 三个事件,与图片的控件容器绑定、即可实现鼠标拖动移动图片位置
private void pbMain_MouseDown(object sender, MouseEventArgs e){photo_rec = photo_show1.GetPictureBoxZoomSize(pictureBox1);pt = Cursor.Position;this.Cursor = Cursors.SizeAll;}private void pbMain_MouseUp(object sender, MouseEventArgs e){this.Cursor = Cursors.Default;int px = Cursor.Position.X - pt.X;int py = Cursor.Position.Y - pt.Y;}private void pbMain_MouseMove(object sender, MouseEventArgs e){if (e.Button == MouseButtons.Left){int px = Cursor.Position.X - pt.X;int py = Cursor.Position.Y - pt.Y;pictureBox1.Location = new Point(pictureBox1.Location.X + px, pictureBox1.Location.Y + py);}pt = Cursor.Position;}}
更多推荐
winform 鼠标拖动移动图片位置
发布评论