i allow drag and drop a picturebox to a panel.
after drag and drop i need to allow the picturebox to remain in its own position and not leaving an empty space there.

how do i do about it?

image.clone does not work.

pls help.thank u.

in sudocode:
onPicturebox MouseDown:

create new picturebox

set new picutebox's size, location, and image properites
to match the old picturebox

StartDraging code moving the new picutebox not the old one.

onMouseUp leave new picutebox where ever you left it/ want it.

    int x;
    int y;
    private Point mouseLocation = new Point(0, 0);
    private PictureBox pictureBox; 
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        pictureBox2.Hide();

    }

    private void pictureBox1_MouseDown_1(object sender, MouseEventArgs e)
    {

        if (e.Button == MouseButtons.Left)
        {
            x = e.X;
            y = e.Y;
        }

        pictureBox = new PictureBox();
        pictureBox.Image = Image.FromFile(@"D:\Documents and Settings\missy ong\Desktop\Model Products 40x40 v2\Model Products 40x40\CCTV\CCTV1Button.jpg");
        pictureBox.Top = 20;
        pictureBox.Width = 16;
        pictureBox.Height = 16;
        pictureBox.Left = 10;
        pictureBox.Location = new Point(12, 24); 

    }

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

            pictureBox1.Left += (e.X - x);
            pictureBox1.Top += (e.Y - y);
            pictureBox1.BringToFront() ;
        }


    }

    //Target picturebox.
    private void panel2_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(typeof(Bitmap)))
        {
            e.Effect = DragDropEffects.Copy;



        }
        else
        {
            e.Effect = DragDropEffects.None;
        }


    }




    private void pictureBox1_MouseHover(object sender, EventArgs e)
    {
        mouseLocation = this.PointToClient(Cursor.Position);
        pictureBox2.Location = mouseLocation;
        pictureBox2.Show();
    }

    private void pictureBox1_MouseLeave(object sender, EventArgs e)
    {
        pictureBox2.Hide();
    }

    private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
    {
        pictureBox.Location = new Point(12, 24);
    }

this is my code. it does not create a new picturebox. could u pls guide? thank u.

rgds.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

you aren't adding the new picture box to the form's controls collection, so it doesn't get painted.

after you set the new picturebox's properties. add

This.Controls.Add(pictureBox);
This question has already been answered. Start a new discussion instead.