Dynamic Control: Drag Handles

528 views Asked by At

I would like to have drag handles for my dynamic pictureBoxes, here is the code of how it was created if it helps:

    private void pictureBox1_Click(object sender, EventArgs e)
    {
        PictureBox flower1 = new PictureBox();
        flower1.Image = Properties.Resources.Flower2;
        flower1.Location = new Point(panel1.Location.X + 10, panel1.Location.Y + 10);
        flower1.Size = new System.Drawing.Size(pictureBox1.Size.Width, pictureBox1.Size.Height);
        flower1.Parent = panel1;
        panel1.Controls.Add(flower1);

        flower1.BringToFront();
        flower1.MouseMove += new MouseEventHandler(flower1_MouseMove);
        flower1.MouseDown += new MouseEventHandler(flower1_MouseDown);
    }

    private void flower1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            MouseDownLocation = e.Location;
        }
    }

    private void flower1_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            PictureBox flower1 = (PictureBox)sender;
            flower1.Left = e.X + flower1.Left - MouseDownLocation.X;
            flower1.Top = e.Y + flower1.Top - MouseDownLocation.Y;
        }
    }

I have no clue how to start. I need to be able to resize these dynamically created images using drag handles. I Googled it and couldn't find anything to do with DYNAMIC controls.

0

There are 0 answers