
![]() |
Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
|
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[3.238.134.157] |
![]() |
|
Сообщ.
#1
,
|
|
|
Есть 2-а picturebox-а и очевидный код для перетаскивания. Но при попытке перенести картинки начинают прыгать по окну((
![]() ![]() private int XDifference; private int YDifference; private bool Selected; private void Element_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && !Selected) { PictureBox pb = (PictureBox)sender; XDifference = pb.Left - e.X; YDifference = pb.Top - e.Y; Selected = true; } } private void Element_MouseMove(object sender, MouseEventArgs e) { if (Selected) { PictureBox pb = (PictureBox)sender; pb.Left = XDifference + e.X; pb.Top = YDifference + e.Y; this.Update(); } } private void Element_MouseUp(object sender, MouseEventArgs e) { Selected = false; } Код откуда-то с форума. |
Сообщ.
#2
,
|
|
|
![]() ![]() private bool isDragging = false; private int currentX; private int currentY; private void pb_MouseMove(object sender, MouseEventArgs e) { if (this.isDragging) { var pb = sender as PictureBox; pb.Top += (e.Y - this.currentY); pb.Left += (e.X - this.currentX); } } private void pb_MouseUp(object sender, MouseEventArgs e) { this.isDragging = false; } private void pb_MouseDown(object sender, MouseEventArgs e) { var pb = sender as PictureBox; if (pb == null) { return; } this.isDragging = true; this.currentX = e.X; this.currentY = e.Y; } |
Сообщ.
#3
,
|
|
|
Спасибо.
|