Question

I am trying to move a pictureBox2 that is in a groupBox2 container to another groupBox1. The problem is that in that container, there is a another pictureBox1 and when I move the pictureBox2 over pictureBox1, pictureBox2 gets a white box around it.

All in all, I want to blend that pictureBox2 to pictureBox1.

Here is my code that incorporates the mouse move, up and down functionality:

    private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
    {
        downPoint = e.Location;
        pictureBox2.Parent = this;
        pictureBox2.BringToFront();

    }

    private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {

            pictureBox2.Left += e.X - downPoint.X;
            pictureBox2.Top += e.Y - downPoint.Y;
        }
    }

    private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
    {
        Control c = GetChildAtPoint(new Point(pictureBox2.Left - 1, pictureBox2.Top));

        if (c == null) c = this;
        Point newLoc = c.PointToClient(pictureBox2.Parent.PointToScreen(pictureBox2.Location));
        pictureBox2.Parent = c;
        pictureBox2.BackColor = Color.Transparent;
        pictureBox2.Location = newLoc;

        this.Refresh();
        pictureBox2.BringToFront();
    } 

I am able to move the pictureBox2 anywhere and assign it a parent, but I can't get it to assign pictureBox1 as its parent, as it only detects the groupBox2 as its parent.

Any help will be appreciated. Thank you. Vincent

Était-ce utile?

La solution

Try setting the PictureBox1.BorderStyle Property to None.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top