CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2009
    Posts
    144

    Dragging picturebox , hides behind panel

    Hello , i want drag and drop to my form , i have some pictureboxes and i want to drag them over the form.

    Code:
            private bool isDragging = false;
            private int currentX, currentY;
    
            private void brown_pictureBox_MouseDown(object sender, MouseEventArgs e)
            {
                isDragging = true;
    
                currentX = e.X;
                currentY = e.Y;
    
                brown_pictureBox.BringToFront();
            }
    
            private void brown_pictureBox_MouseMove(object sender, MouseEventArgs e)
            {
                if (isDragging)
                {
                    brown_pictureBox.Top = brown_pictureBox.Top + (e.Y - currentY);
                    brown_pictureBox.Left = brown_pictureBox.Left + (e.X - currentX);
                }
            }
    
            private void brown_pictureBox_MouseUp(object sender, MouseEventArgs e)
            {
                isDragging = false;
            }
    i use this code and it works very good , now i have a problem , i placed the pictureboxes inside a panel and now when i drag them out of it , the pictureboxes hides behind the panel.....

    i tried brown_pictureBox.BringToFront(); but nothing happened.

  2. #2
    Join Date
    Jun 2011
    Location
    Buenos Aires, Argentina
    Posts
    130

    Re: Dragging picturebox , hides behind panel

    Try adding the pictureBox to the Panel.Controls so that it is shown inside it. Maybe they are set as part of the forms Controls.
    Did you try Panel.SendToBack()? Not sure if it would have a different effect as the pictureBox BringToFront... but it's worth trying.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured