动态控制:拖动手柄

时间:2013-08-29 18:22:58

标签: c# drag picturebox handles

我想为我的动态pictureBox提供拖动句柄,如果它有帮助,这里是如何创建它的代码:

    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;
        }
    }

我不知道如何开始。我需要能够使用拖动手柄调整这些动态创建的图像的大小。我用Google搜索,无法找到与DYNAMIC控件有关的任何内容。

0 个答案:

没有答案