ポイントmouseDownPoint = Point.Empty。 長方形RECT = Rectangle.Empty。 BOOL isDrag = 偽; プライベート ボイド pictureBox1_MouseDown(オブジェクト送信者、MouseEventArgs E) { 場合(e.Button == MouseButtons.Left) { mouseDownPoint = e.Location。 RECT = pictureBox1.Bounds。 } } プライベート ボイド pictureBox1_MouseUp(オブジェクト送信者、MouseEventArgs E) { 場合(e.Button == MouseButtons.Left) { 場合(isDrag) { isDrag = 偽。 pictureBox1.Location = rect.Location。 この.Refresh(); } )(リセット。 } } プライベート ボイド pictureBox1_MouseMove(オブジェクト送信者、MouseEventArgs E) { 場合(e.Button == MouseButtons.Left) { isDrag = 真。 rect.Location = getPointToForm(新しいポイント(e.Location.X - mouseDownPoint.X、e.Location.Y -mouseDownPoint.Y)); この.Refresh(); } } プライベート ボイドリセット() { mouseDownPoint = Point.Empty。 RECT = Rectangle.Empty。 isDrag = 偽; } プライベートポイントgetPointToForm(点P) { 戻り 、この(pictureBox1.PointToScreen(P))を.PointToClient。 }
ドラッグして制御位置を変更します
おすすめ
転載: www.cnblogs.com/jizhiqiliao/p/10930612.html
おすすめ
ランキング