0

我想为我的动态图片框设置拖动句柄,如果有帮助,这里是如何创建它的代码:

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

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

4

0 回答 0