На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS
msm.ru
  
> Перетаскиваемый PictureBox
    Есть 2-а picturebox-а и очевидный код для перетаскивания. Но при попытке перенести картинки начинают прыгать по окну((
    ExpandedWrap disabled
              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;
              }


    Код откуда-то с форума.
      ExpandedWrap disabled
        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;
        }
        Спасибо.
        0 пользователей читают эту тему (0 гостей и 0 скрытых пользователей)
        0 пользователей:


        Рейтинг@Mail.ru
        [ Script execution time: 0,0185 ]   [ 16 queries used ]   [ Generated: 26.04.24, 07:09 GMT ]