1

所以我正在尝试制作一个拖放应用程序,可以在面板上拖动某些东西。我以前做过,但我忘记了我用于它的代码。我也希望它有一个活动。这是一个失败的例子:

    private void pictureBox1_Click(object sender, EventArgs e)
    {
        PictureBox flower1 = new PictureBox();
        flower1.Image = pictureBox1.Image;
        flower1.Location = new Point(panel1.Location.X, panel1.Location.Y);
        flower1.Width = 100;
        this.Controls.Add(flower1);
        flower1.MouseDown += new MouseEventHandler(flower1_MouseDown);
    }

    void flower1_MouseDown(object sender, MouseEventArgs e)
    {
        //flower1.Location = new Point(MousePosition.X, MousePosition.Y);
    }

我想让我单击一朵花,然后将其放置在面板上,然后,如果鼠标单击复制到面板上的控件,则将该位置设置为鼠标光标的位置。我该怎么做呢?它甚至没有出现重复。

编辑:刚刚意识到图像位于面板下方,因此无法看到。这是一个问题,现在我如何让它拖放?

4

1 回答 1

0
private void pictureBox1_Click(object sender, EventArgs e)
{
    PictureBox flower1 = new PictureBox();
    flower1.Image = pictureBox1.Image;
    flower1.Location = Point.Empty;
    flower1.Width = 100;
    flower1.Parent = panel1;
    flower1.MouseDown += new MouseEventHandler(flower1_MouseDown);
}
于 2013-08-29T16:37:55.143 回答